Use Common Error Pages for the Whole Application
The JSP
page directive’s
errorPage
attribute can be used to specify a page to be invoked when an error
occurs while processing the page. The page can be a static HTML file,
a servlet, or a JSP page. A JSP page used as an error page
(designated as such by the page
directive’s
isErrorPage
attribute) has access to a
Throwable instance that represents the error
through the implicit
exception
scripting variable, or through
the EL expression ${pageContext.exception}.
While this mechanism might be suitable for a small application using
only JSP pages, it’s not appropriate for an
enterprise application using a combination of servlets, filters, and
JSP pages. Using a shared error handler for all these component types
lets you better control error handling and fine-tune it in one place
when needed. To use a global error handler, do not use the
errorPage attribute in the JSP pages. Instead,
declare an error handler in the web application deployment descriptor
(the web.xml file):
<web-app>
. . .
<servlet>
<servlet-name>errorHandler</servlet-name>
<servlet-class>
com.ora.jsp.servlets.ErrorHandlerServlet
</servlet-class>
<init-param>
<param-name>errorPage</param-name>
<param-value>/shared/error.html</param-value>
</init-param>
</servlet>
. . .
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errorHandler</location>
</error-page>
. . .
</web-app>Here, I define a servlet as the error handler for all types of exceptions; ...