Tomcat error page

Java web pages running on a Tomcat server may cast errors like NullPointerExceptions, causing the execution of the web page to fail. Additionally, errors may occur outside of web page execution, eg a File-not-found error caused by the user's URL request not being resolved to any existing part of a web page. The goal is to deliver a specific custom page when an error occurs on a Tomcat server.
1 answer

Error-page element in web.xml

You can add error-page elements to your project-specific web.xml to tell Tomcat which page to display in case an error occurs. Note that these error pages will be displayed outside of any framework context, eg the statefulness of Spring Web Flow will not be available in an error page.

Example:
<web-app ...>
  <error-page>
    <error-code>404</error-code>
    <location>/jsp/error_404.jsp</location>
  </error-page>
  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/jsp/error.jsp</location>
  </error-page>
</web-app>

Taggings: