• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem displaying exceptions

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm in the process of implementing a declarative exception handler for my Struts web app. The code passes the exception to the handler properly and finds exception.jsp properly, but I can't get my messages to appear on exception.jsp. Here is what my configuration looks like:

<global-exceptions>
<exception
type="java.lang.Throwable"
key="exception.details"
handler="pkg.exceptions.ExceptionHandler"
path="/exception.jsp"/>
</global-exceptions>

I have a key in my MessageResources.properties file called 'exception.details' and it's value is set to {0} or just whatever message is passed in. In my exception handler, I'm calling storeException() as such:

storeException(request, "exception.details", new ActionMessage(ex.getMessage()), new ActionForward(ae.getPath()), ae.getScope());

I can see the exception message being stored in the request attributes just after the storeException() method call, so I know it's there.

I've tried numerous things to get the message to display on exception.jsp, but nothing works.

Any ideas? Thanks.
[ March 01, 2007: Message edited by: Bryan Comstock ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just let the default Struts code in the ExceptionHandler superclass handle the error message? I'd suggest just doing whatever logging or extra activities you need to do in your execute method, and then just end the method with:

This will handle putting the error message in either the request or the session and passing the exception message as the first parameter

Then in your JSP, just display the errors with either a <html:errors /> tag or a combination of <html:messages> and <bean:write> tags.
 
Bryan Comstock
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions Merrill. I may end up switching back to allowing Struts to handle it..

My main issue is actually getting the error message to appear on my page, though. I've tried using <html:errors/> and <html:messages>, but neither of them show the message.

If I use <html:messages> does the property need to be the key that I defined or some global key?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the case of both <html:errors> and <html:messages> you should not specify a property attribute at all. This will display all available messages, which is what you want.

If <html:errors> didn't work, that may be an indication that you didn't set the message properly. Try letting Struts set the message as described above, and see if that fixes it.
[ March 01, 2007: Message edited by: Merrill Higginson ]
 
Bryan Comstock
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, thanks to your help I got the messages displaying now. I changed my exception handler to just call super.execute() and then both <html:errors/> and <html:messages> (without a property) displayed the messages.

Thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic