2 Minutes To Code (β Version)

Apache Tomcat - 2 minute tutorial

Error Pages : How to configure error pages to handles exceptions and http error status codes

If your web-app throws an exception that you are not catching anywhere, then it will be sent to the web browser and end up either confusing or putting off you end-user.

So, a web-app should handle exceptions gracefully. In the deployment description (web.xml), you can tell the tomcat that if a particular exception is thrown or a partcular http status code is generated, then it should let a configured servlet/jsp handle it instead of sending the exception to the end-user. The elements for this configuration are <error-page>, <exception-type>, <location> & <error-code> as shown in the examples below.

 <web-app>
    
    <error-page>
        <exception-type>java.lang.Exception </exception-type>
        <location>/error/exceptionPage.jsp </location>
    </error-page>

    <error-page>
        <exception-type>java.lang.NullPointerException </exception-type>
        <location>/error/nullPointerPage.jsp </location>
   </error-page>

 </web-app>
 <web-app>
    
     <error-page>
         <error-code>404 </error-code>
         <location>/error/pageNotFound.jsp </location>
     </error-page>

 </web-app>