Java Reference
In-Depth Information
Figure 13.2: A nicer way of recovering from an exception
Download email_28/web/WEB-INF/jsp/exception.jsp
<fmt:message var="title" key="exception.title"/>
<s:layout-render name="/WEB-INF/jsp/common/layout_main.jsp"
title="${title}">
<s:layout-component name="body">
<p>
<fmt:message key="exception.message"/>
</p>
<s:link href="/">
<fmt:message key="exception.startOver"/>
</s:link>
</s:layout-component>
</s:layout-render>
Going to /Admin.action now displays the page shown in Figure 13.2 .
Ahh, much nicer!
Extending DefaultExceptionHandler
Stripes also provides the DefaultExceptionHandler class, which we can
extend and benefit from a few niceties. First, we can return a Resolution
after the exception-handling code, which makes it simpler to redirect
to another action bean, add request parameters, and so on. Second,
with DefaultExceptionHandler we can handle different types of exceptions
very easily. Just add a method that accepts exactly three parameters:
the exception type, the HttpServletRequest , and the HttpServletResponse .
When an exception occurs, Stripes automatically uses the method that
handles the specific exception type or the closest match going up the
exception's class hierarchy. This lets us have a method that generically
handles Throwable (the top of the exception hierarchy) for all exceptions
and adds methods that handle more specific exceptions in different
ways.
 
 
 
Search WWH ::




Custom Search