用thymeleaf浏览器404问题中之一bug

用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值