You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andy <an...@hotmail.com> on 2009/01/20 18:49:34 UTC
Handling JSP exceptions in Struts2
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?
_________________________________________________________________
Windows Live™: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009
Re: Handling JSP exceptions in Struts2
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 26/01/09 21:21, wrote:
> Andy wrote:
> > it appears that the Exception interceptor will fire after
> > the Result has completed, which would theoretically catch
> > any exceptions thrown by the JSP.
>
> It's not that it fires "after" the result is completed, it's that
> everything happens *within* the interceptors: they're wrapped around the
> result (that's why there are PreResultListeners, in fact).
>
Good point Dave. I always forget to check if there's already an interceptor to
do what I need in S2 - and generally, there is, or if not, it's easy to extend
the interceptor to add what you need.
So I have to eat my words in answer to your first question because yes, struts2
will handle it. I assume that you can configure the Exception interceptor to
pick up particular JspExceptions and send the flow of control to your desired
result. The online docs should sort you out there.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Handling JSP exceptions in Struts2
Posted by Dave Newton <ne...@yahoo.com>.
Andy wrote:
> it appears that the Exception interceptor will fire after
> the Result has completed, which would theoretically catch
> any exceptions thrown by the JSP.
It's not that it fires "after" the result is completed, it's that
everything happens *within* the interceptors: they're wrapped around the
result (that's why there are PreResultListeners, in fact).
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Handling JSP exceptions in Struts2
Posted by Andy <an...@hotmail.com>.
> Hellow,> I am using struts2.0 in my project.I am getting all error messages after> submitting the form.> But i am not getting the error messages in proper order as the fields order> in form.> please let me know how to solve this one.please tell me if any of you know.> > Regards> Nageswara Rao
Please dont hijack threads, start your own.
> Date: Mon, 26 Jan 2009 22:50:45 -0800> From: nagesh@btpsoft.com> To: user@struts.apache.org> Subject: RE: Handling JSP exceptions in Struts2> > > > > Andy Hahn wrote:> > > > > > 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.struts@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.struts@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-unsubscribe@struts.apache.org For additional> >> >> commands, e-mail: user-help@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-unsubscribe@struts.apache.org> >> For additional commands, e-mail: user-help@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> > > > > > > Hellow,> I am using struts2.0 in my project.I am getting all error messages after> submitting the form.> But i am not getting the error messages in proper order as the fields order> in form.> please let me know how to solve this one.please tell me if any of you know.> > Regards> Nageswara Rao> > > -- > View this message in context: http://www.nabble.com/Handling-JSP-exceptions-in-Struts2-tp21568108p21680499.html> Sent from the Struts - User mailing list archive at Nabble.com.> > > ---------------------------------------------------------------------> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org> For additional commands, e-mail: user-help@struts.apache.org>
_________________________________________________________________
Windows Live™ Hotmail®:…more than just e-mail.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore_012009
RE: Handling JSP exceptions in Struts2
Posted by Naaag <na...@btpsoft.com>.
Andy Hahn wrote:
>
>
> 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.struts@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.struts@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-unsubscribe@struts.apache.org For additional
>> >> commands, e-mail: user-help@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-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@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
>
Hellow,
I am using struts2.0 in my project.I am getting all error messages after
submitting the form.
But i am not getting the error messages in proper order as the fields order
in form.
please let me know how to solve this one.please tell me if any of you know.
Regards
Nageswara Rao
--
View this message in context: http://www.nabble.com/Handling-JSP-exceptions-in-Struts2-tp21568108p21680499.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Handling JSP exceptions in Struts2
Posted by Andy <an...@hotmail.com>.
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.struts@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.struts@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-unsubscribe@struts.apache.org For additional
> >> commands, e-mail: user-help@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@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
Re: Handling JSP exceptions in Struts2
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
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.struts@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-unsubscribe@struts.apache.org For additional
>> commands, e-mail: user-help@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Handling JSP exceptions in Struts2
Posted by Andy <an...@hotmail.com>.
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.struts@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@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
Re: Handling JSP exceptions in Struts2
Posted by Adam Hardy <ah...@cyberspaceroad.com>.
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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org