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 相关依赖项已经正确配置和安装好了且版本兼容。
相关文章
|
3月前
Error:(56, 18) 错误: com.newCallblack.callshow.util.DownloadUtil cannot be provided without an @Inject
Error:(56, 18) 错误: com.newCallblack.callshow.util.DownloadUtil cannot be provided without an @Inject
18 0
|
9天前
|
Java Maven
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
16 0
|
3月前
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
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
395 0
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
|
缓存 Ubuntu Java
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
383 0
‘settings.xml’ has syntax errors less… 和Parent ‘org.springframework.boot’has problems less…的问题解决
|
1月前
|
Java 数据库连接 mybatis
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid
|
3月前
|
XML Java 数据库连接
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
40 1
|
10月前
|
XML Java 数据库连接
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
131 0