Hey there!
I have a question for you guys.
When an exception is thrown in my Action derivative I want that exception
to
be handled by the errorpage (<%@ page isErrorPage="true %>). After fooling
around
with the web.xml file adding entries such as:
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/errorpage.jsp</location>
</error-page>
the result is that when I throw a ServletException from the Action.perform
method
I'm directed to my login page(?!). I've tried using the
"mapping.findForward" approach,
as in:
public final ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
ActionForward af = null;
try {
af = doPerform(...); // throws exception
} catch(Throwable t) {
request.setAttribute("javax.servlet.jsp.jspException", new
ServletException(t));
af = mapping.findForward("error");
}
return af;
}
ofcourse, I added:
<!-- ========== Global Forward Definitions
============================== -->
<global-forwards>
<forward name="error" path="/errorpage.jsp"/>
</global-forwards>
to the struts-config.xml file.
That didn't work either. The only approach that seems to work for me is:
public final ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
try {
return doPerform(...); // throws exception
} catch(Throwable t) {
request.setAttribute("javax.servlet.jsp.jspException", t);
getServlet().getServletContext().getRequestDispatcher
("/errorpage.jsp").forward(request, response);
}
}
Now my questions are:
Is this last approach safe to use with Struts?
How do you guys accomplish this? Do you use a different approach
altogether?
TIA,
S. Bro