• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Page

 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jobin Mathew
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic