有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

jsp如何在Java中捕获HTTP 404

我有一个web应用程序,我有一个问题 如果我的应用程序中不存在该网页,我将得到以下错误页面

HTTP Status 404 - /myapplication/department/home.html

type Status report

message /myapplication/department/home.html

description The requested resource (/myapplication/department/home.html) is not available.

我想把用户转发到索引页,如果这个问题发生了,他不知道怎么做


共 (1) 个答案

  1. # 1 楼答案

    只需在web.xml中将索引页指定为404默认错误页

    <error-page>
        <error-code>404</error-code>
        <location>/index.jsp</location>
    </error-page>
    

    我假设你知道这对用户体验和SEO不好?例如,如果您已经(重新)移动了一个页面,那么您应该创建一个过滤器,将301重定向到所需的位置