aspose file tools*
The moose likes Struts and the fly likes Error Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error Page" Watch "Error Page" New topic
Author

Error Page

Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Hi,
I used the following tag to handle errors.
<global-exceptions>
<exception key="errors.msg" type="java.lang.Exception" path="/template/error.jsp"/>
</global-exceptions>


and in JSP page I put <%@page isErrorPage="true"%>

but in the JSP page the exception variable is null.
Why it is null? So how can I know more details about the exception, like stacktrace....
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Don't confuse the Struts error handler with the JSP error handler. They're not the same thing. The Struts Error handler is invoked by Struts if an uncaught exception is thrown in an Action or ActionForm class. The JSP error handler is invoked if an uncaught exception is thrown in a JSP. The one has nothing to do with the other. Since your JSP was invoked by the Struts error handler, and not the JSP error handler, the JSP exception variable is naturally going to be null.

A fact that's not well documented is that the global exception handler will pass information on the underlying exception that was caught as the first parameter to your message. You can therefore capture it and display it in your JSP just by including an <html:errors /> tag.

In your messages properties file, your message would look something like this:

The {0} parameter is then filled in by the Struts error handler.


Merrill
Consultant, Sima Solutions
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Thanks Merrill.

But I want to log all the exceptions. Also I need to log the stacktrace. Is there any way for that?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In that case, you'll have to write your own extension to the Strus Exception Handler.
[ April 11, 2008: Message edited by: Merrill Higginson ]
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Thanks Merrill
And one more thing, Is this the right way of doing that?
Or this is a quick & dirty solution?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I think using the global exception handler is a good way to go. It saves you coding try/catch blocks in all your actions, and gives you a central place to handle logging of exceptions.
Jobin Mathew
Ranch Hand

Joined: Oct 17, 2006
Posts: 83
Thanks Merrill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Page