浏览器报错信息:
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template="index", line 58 - column 28
后台报错信息:
ERROR 72788 --- [nio-8086-exec-1] o.thymeleaf.templateparser.ErrorHandler : [THYMELEAF][http-nio-8086-exec-1] Fatal error during parsing
org.xml.sax.SAXParseException: 元素内容必须由格式正确的字符数据或标记组成。
ERROR 72788 --- [nio-8086-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8086-exec-1] Exception processing template "index": Exception parsing document: template="index", line 58 - column 28
ERROR 72788 --- [nio-8086-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/energymanagement] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template="index", line 58 - column 28] with root cause
程序代码信息:定位到Html页面中的代码,如下图
问题详解及处理方式:
Springboot支持thymeleaf、freemarker、JSP,但是官方不建议使用JSP,因为有些功能会受限制。
1、在pom.xml中添加依赖,指定前台模版:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、开发的时候要关闭模板缓存,不然修改界面文件后无法实时显示。在application.properties文件中关闭模板缓存:
spring.thymeleaf.cache = false
3、编写前台界面:
注意:在编写html页面的时候,如果不加 <!DOCTYPE html> 这个声明,就会出现一开始的那个错误。
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title</title>
</head>
<body>
Hello World!
</body>
</html>