I have kind of sorted this out.. My goal is simple - I don't ever want my users to see errors caused by actions or jsps, and I want to be able to record every error.
My configuration is struts 2.1.6, struts-spring-plugin, struts-tiles-plugin, hibernate, jsp, tomcat. This topic seems to be seldom fully covered, in particular for S2. Many people recommend either defining an error-page in web.xml or using global exception mappings. I have resorted to using the latter, and so far it has been catching both action and jsp exceptions. From looking at Figure 1.4 on page 15 of Struts 2 In Action, it appears that the Exception interceptor will fire after the Result has completed, which would theoretically catch any exceptions thrown by the JSP. And that seems to be happening for me. I would have expected Struts 2 to have to hand off control of the JSP to the container at some point but who knows how its working its magic. So I guess my solution is to use a global exception mapping and skip the web.xml error-page. I then record the exception details in a service and then redirect to an Action which renders a generic error page JSP. So far so good. If anyone has any thoughts, please let me know. Thanks! > Date: Mon, 26 Jan 2009 14:21:39 +0000 > From: ahardy.str...@cyberspaceroad.com > To: user@struts.apache.org > Subject: Re: Handling JSP exceptions in Struts2 > > Did you sort this out already Andy? > > I can't remember whether the web.xml error page is the same mechanism as the > error page declaration. > > As for grabbing the exception object, I guess it must be in some servlet > container scope like the request attributes under some key or other. > > You could even use an interceptor to check for exceptions after the result. > > Sorry I can't be more specific, I guess it leaves up to you to try out > different > strategies. Presuming that you're not using templating of any kind since you > didn't mention it, it shouldn't be too difficult. But you also didn't say > what > the problem was with your web.xml approach. > > I can see you having problems though if you don't buffer your response. > > Regards > Adam > > Andy on 22/01/09 14:18, wrote: > > Thanks for the response. What I'd like to do is allow an action to handle > > the JSP exception instead of a JSP, so that I can save the exception to the > > DB and then redirect the user to an error page. The problem I am having is > > trying to get the exception object to pass to the action. This is what I > > was > > trying to use (web.xml): > > > > <error-page> <exception-type>java.lang.Exception</exception-type> > > <location>/canvas.action</location> </error-page> > > > > > > > >> Date: Thu, 22 Jan 2009 11:19:35 +0000 From: > >> ahardy.str...@cyberspaceroad.com To: user@struts.apache.org Subject: Re: > >> Handling JSP exceptions in Struts2 > >> > >> Andy on 20/01/09 17:49, wrote: > >>> Using the Exception interceptor works great for catching exceptions throw > >>> by actions. However I am wondering what is the recommended method for > >>> catching and handling exceptions thrown by a JSP? I assume that JSP > >>> exceptions are outside the S2 scope and are to be handled at the > >>> container level? > >> Assumption correct. > >> > >> Your situation might be quite simple if you have a basic JSP. Put in an > >> error declaration > >> > >> <%@ page errorPage="/WEB-INF/jsp/error.jsp" %> > >> > >> and handle it there. > >> > >> If you're using multiple JSPs with a templating system like tiles, it gets > >> more complicated. I do and I put a meta-redirect in my error JSP so that > >> the browser doesn't show the mix of correct and broken fragments. > >> > >> --------------------------------------------------------------------- To > >> unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional > >> commands, e-mail: user-h...@struts.apache.org > >> > > > > _________________________________________________________________ Windows > > Live™: E-mail. Chat. Share. Get more ways to connect. > > http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_allup_explore_012009 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > _________________________________________________________________ Windows Live™: E-mail. Chat. Share. Get more ways to connect. http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_allup_explore_012009