Last-resort exception reporting using an error page

In order to report all uncaught exceptions in a JSP/servlet application, which occur during the execution of an UI-event-triggered action, it is sufficient to install one central error page. See section 2.4.2 Request Time Processing Errors of the Sun Java Server Pages Specification about this.

In Tomcat you can do this in the deployment descriptor web.xml by an <error-page> directive. E.g.:

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/system/errorPage.jsp</location>
</error-page>

This means, that any exception, including Throwable, will be reported by forwarding to the JSP page /system/errorPage.jsp. The error page itself must be marked as such by setting the page directive's isErrorPage attribute to true, e.g.:

<%@page contentType="text/html" isErrorPage="true" %>        

In such an error page you should report not only the message texts of the exception chain, but also it's stack trace and diagnostically useful attributes of the request, session, and application.

See an example at the Central Exception Reporting Sample Application, site https://app.assembla.com/spaces/excrep/git/source