How to catch a HTTP 404 in Java
I have a web application and I have a problem If the web page does not exist in my application I have got the following error page
HTTP Status 404 - /myapplication/department/home.html
type Status report
message /myapplication/department/home.html
d开发者_JS百科escription The requested resource (/myapplication/department/home.html) is not available.
I want to forward user to the index page, if this problem happen , without he knows How to do that
Just specify the index page as 404 default error page in web.xml
.
<error-page>
<error-code>404</error-code>
<location>/index.jsp</location>
</error-page>
I assume that you are aware that this is bad for user experience and SEO? If it is for example a page which you have (re)moved, then you should rather create a filter which does a 301 redirect to the desired location.
精彩评论