Using Standard Web Application Error Handling
A JSF application is also a servlet-based application, so truly exceptional runtime exceptions can be trapped and handled by error handlers declared in the web.xml file:
<web-xml>
...
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errorpage.jsp</location>
</error-page>
...
</web-xml>The <error-page> element
contains an
<exception-type> element that names an
exception type and a <location> element with
a context-relative path for the resource to invoke if the exception
is thrown by any request. The resource can be a JSP page or servlet
that displays a friendly message instead of the stack trace most web
containers show by default. It can also log information about the
error, available as request scope attributes as well as through the
implicit pageContext variable in a JSP page. If
you need to deal with different types of exceptions in different
ways, you can declare more than one error handler. The web container
picks the one with an exception type that most closely matches the
thrown exception. For more on all of this, I recommend my book
JavaServer Pages (O’Reilly).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access