*
The moose likes Struts and the fly likes Struts 2 Exception Handling Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 Exception Handling Question" Watch "Struts 2 Exception Handling Question" New topic
Author

Struts 2 Exception Handling Question

Chhaya Patil
Greenhorn

Joined: Nov 14, 2008
Posts: 17
Hi,

I am trying to use Struts2 exception handling mechanism.
Here is how my struts.xml file looks like for exception related entries -

<global-results>
<result name="Exception">/pages/error.jsp</result>
</global-results>

<global-exception-mappings>
<exception-mapping exception="java.sql.SQLException" result="SQLException" />
<exception-mapping exception="java.lang.Exception" result="Exception" />
</global-exception-mappings>

Here is my action related entry -
<action name="abc"
class="com.action.abc">
<interceptor-ref name="exception" />
<interceptor-ref name="abcStack" />
<result>/pages/packets.jsp</result>
</action>

Now in my Action class when i get an exception i return "Exception" . ( I am not sure this is the way to do it, i am pretty new to Struts2.)
My error.jsp pages gets displayed but i do not see any exception message and stack trace.
I have <s:property value="%{exception.message}"/> , <s:property value="%{exceptionStack}"/> for displaying error msg and stack trace.

Does anyone have idea where i am getting wrong?

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't think *you* have to return "Exception", the only reason the exception result is named is so it can be referred to in the exception mappings: if the action throws the exception the framework handles mapping the exception to the result.

Also, if you map directly to a JSP I'm not sure that the <s:property> tags will work--if there's no action there may not be a value stack from which to retrieve the values. Try instead a "redirectAction", which can be a classless action mapping.
Chhaya Patil
Greenhorn

Joined: Nov 14, 2008
Posts: 17
Thanks for replying.

the exception is from outside the execution of the action logic. it's from a data access class which i call from action. So i was getting 1 or 0 depending on success or failure from data access module. So if data acceess component had exception it was returning 1 and i was returning "Exception". which is wrong.

So now just to try, i copied the exception causing DB code into action itself and i am not returning "Exception". But when exception is occuring i see 500 error page but not Error.jsp with stack trace. So the entire exception trapping is not working. Any idea why?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 Exception Handling Question
 
Similar Threads
struts2: what kicks in first- the interceptors or the form's validation?
ModelDriver Interceptor + not getting my object
Global Exception handling issue in Struts2
struts2 + interceptor
Interceptor messes up action class in Struts2