wood burning stoves 2.0*
The moose likes Struts and the fly likes Problem displaying exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem displaying exceptions" Watch "Problem displaying exceptions" New topic
Author

Problem displaying exceptions

Bryan Comstock
Greenhorn

Joined: Mar 01, 2007
Posts: 5
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 ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Bryan Comstock
Greenhorn

Joined: Mar 01, 2007
Posts: 5
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Mar 01, 2007
Posts: 5
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem displaying exceptions