This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts 2 Exception Handling Question

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

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

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

Here is my action related entry -
<action name="abc"
<interceptor-ref name="exception" />
<interceptor-ref name="abcStack" />

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?

Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic