用thymeleaf-----浏览器404问题
问题:
**HTTP Status 404 – Not Found
Type Status Report
Message /thymeleaf_war_exploded/
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.31**
分析原因:
首先404 是index.html(或者是index.jsp)文件找不到
接着我们一块捋一捋思路:
启动tomcat服务器,服务器在web下面找index.html
(注意:WEB-INF下面的文件是无法从浏览器中直接访问的,必须经过服务器才能访问到WEB-INF下面的文件)
由于index.html放入WEB-INF中,tomcat只能去servlet中找
服务器先读取配置文件web.xml
找到了问题: <url-pattern>/index</url-pattern>
<servlet>
<servlet-name>ToindexServlet</servlet-name>
<servlet-class>com.servlet.ToindexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ToindexServlet</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
如果配置文件没有问题,就检查servlet中是否有错误。
public class ToindexServlet extends ViewBaseServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("访问到了indexservlet。。。");
this.processTemplate("index",request,response);
}
}
很明显servlet 中没有错误。
解决方案:
<servlet>
<servlet-name>ToindexServlet</servlet-name>
<servlet-class>com.servlet.ToindexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ToindexServlet</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>
在web.xml配置文件中的/index.html
可以在重启tomcat时候让服务器放问到index.html
以上就是笔者遇到的404