Redirect from unavailable resource in Tomcat
I develop a web application on Apache Tomcat (Version 7) using JSF2. End users will probably fidget around with the address bar of a web application. I want to impose a default behavior on cases when users either call for a subpage that does not exist (which normally leads to a Tomcat file-not-found page ("The requested resource () is not available."
) or call the application without specifying a startpage (like http://localhost:8080/App/
). My desired behavior would be to redirect the user to a custom page with more telling information than a default server error message.
I have not figured out an available link between my JSF application and Tomcat. I tried to solve this problem u开发者_JAVA百科sing a Phase Listener, but it does not work - as no page associated with my application is requested. How to achieve this in the aforementioned technological environment?
You can specify your own errorpages in the deployment descriptor (web.xml):
Errorpages in web.xml
You can even define Exception-specific error pages, i.e. if you want to display an error-page for the infamous ViewExpiredException.
I hope this helps!
You can define the location of a custom HTTP 404 error page in web.xml
.
<error-page>
<error-code>404</error-code>
<location>/errorpages/404.html</location>
</error-page>
精彩评论