org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template

简介: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template

编译软件:IntelliJ IDEA 2019.2.4 x64

操作系统:win10 x64 位 家庭版

服务器软件:apache-tomcat-8.5.27

报错信息


一、报错信息分析

将报错信息抽取出来:

①org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: “/WEB-INF/pages/index.html”)

上述报错信息是Thymeleaf模板解析异常,简而言之,Thymeleaf解析"/WEB-INF/pages/index.html"时出现了异常

②java.io.FileNotFoundException: ServletContext resource “/WEB-INF/pages/index.html” does not exist

上述报错表明”/WEB-INF/pages/index.html“不存在,服务器找不到该资源。

基于上述报错信息,我对比查找了我的web.xml关于index.html的访问路径,反复查验分析访问路径,结果访问路径是对的,代码逻辑也没有问题,删掉之前的war包然后重新编译war包,重启Tomcat服务器,还是报刚才的错误。

后来我对比了我的本地动态web项目的index.html的实际存储位置 ,分析并找到了原因,如下所示:

解决方案:将index.html移动至WEB-INF/apges 目录下,要让index.html置于Thymeleaf可以找到的位置上【即要放在Thymeleaf在web.xml中设置的前缀下 ”/WEB-INF/pagges/“


二、可能存在的错误原因

  • 文件路径错误在代码中指定的文件路径可能存在错误,导致无法找到正确的文件。解决方法是检查文件路径是否正确,并进行必要的更正
  • 资源缺失或不正确部署WEB-INF 目录下的资源可能没有被正确部署到服务器上或者被删除了。解决方法是检查 WEB-INF 目录下的文件是否正确部署,并确保文件的读取权限正确。
  • 控制器[Servlet]代码错误可能是控制器代码中存在的逻辑错误或异常,导致模板无法正确解析。解决方法是检查相应的代码逻辑。(ps:我这里用到是servlet)
  • Thymeleaf 库或版本问题可能是所使用的 Thymeleaf 库或其版本与应用程序不兼容,导致无法正确处理模板。 解决方法需要确保所有的 Thymeleaf 相关依赖项已经正确配置和安装好了且版本兼容。
相关文章
|
6月前
An error happened during template parsing (template: “ServletContext resource [/WEB-INF/templates/in
An error happened during template parsing (template: “ServletContext resource [/WEB-INF/templates/in
IDEA添加Swagger2:Parameter 0 of method linkDiscoverers in org. springframework hateoas.config.Hateoasconfiguration required a single bean, but 15 were found:
IDEA添加Swagger2:Parameter 0 of method linkDiscoverers in org. springframework hateoas.config.Hateoasconfiguration required a single bean, but 15 were found
|
6月前
|
前端开发 Java 数据库连接
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
130 0
|
6月前
|
Java
org.springframework.web.util.NestedServletException: Request processing failed; nested exception....
org.springframework.web.util.NestedServletException: Request processing failed; nested exception....
152 0
|
6月前
|
Java Spring
spring-doc报错Unable to render this definition
spring-doc报错Unable to render this definition
419 0
|
Java Spring
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
|
JavaScript 前端开发
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression...
144 0
|
Java 测试技术 Spring
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml
837 0