Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中捕获HTTP 404_Java_Jsp - Fatal编程技术网

如何在Java中捕获HTTP 404

如何在Java中捕获HTTP 404,java,jsp,Java,Jsp,我有一个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 avai

我有一个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.

我想将用户转发到索引页,如果出现此问题,而他不知道如何做

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


404
/index.jsp

我假设你知道这对用户体验和SEO不好?例如,如果某个页面已(重新)移动,则您应该创建一个筛选器,该筛选器将301重定向到所需位置。

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


404
/index.jsp

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

非常感谢。如果index.jsp位于home.html页面上的一个文件夹中,该怎么办。我试图编写../index.jsp,但它不起作用。你能告诉我如何在URL中后退一步吗?给定的示例应该已经做到了。前导斜杠
/
使其相对于webapp的上下文根。它将显示
/myapplication/index.jsp
。我尝试将其显示为/myapplication/department/index.jsp。这只能意味着您使用
index.jsp
而不是
/index.jsp
。或者链中一定有一些过滤器干扰了请求/响应,或者使用的容器中存在一些错误。非常感谢。如果index.jsp位于home.html页面上的一个文件夹中,该怎么办。我试图编写../index.jsp,但它不起作用。你能告诉我如何在URL中后退一步吗?给定的示例应该已经做到了。前导斜杠
/
使其相对于webapp的上下文根。它将显示
/myapplication/index.jsp
。我尝试将其显示为/myapplication/department/index.jsp。这只能意味着您使用
index.jsp
而不是
/index.jsp
。或者链中一定有干扰请求/响应的过滤器,或者使用的容器中有一些bug。