File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Globals.EXCEPTION_KEY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Globals.EXCEPTION_KEY" Watch "Globals.EXCEPTION_KEY" New topic


Sanjay Virkar

Joined: Apr 03, 2005
Posts: 19
I want to use default exception handler and don't want to customize it.
In my struts-config.xml file have defined global exception as follows.
<exception bundle="ApplicationResources"
path="/WEB-INF/jsp/errorpg.jsp" >
<exception bundle="ApplicationResources"
path="/WEB-INF/jsp/errorpg.jsp" >

In errorpg.jsp, I am trying to display the key passed to errorpg.jsp as follows( Note: First two lines are entered for debugging) -

<%= request.getAttribute("Globals.EXCEPTION_KEY") %><fmt:message key="errorpg.msg.sorryerror">
<fmt aram value='${Globals.EXCEPTION_KEY}'/>

In ApplicationResources file "errorpg.msg.sorryerror" is defined as
"Sorry, for following reason we cant continue. Reason- {1} "

When exception is generated, errorpg.jsp is displayed as expected but the message I get is-

null Sorry, for following reason we cant continue. Reason- {1}

So for some reason Globals.EXCEPTION_KEY does not contain anything. Can you tell me what am I doing wrong? Is there something I need to set which will populate Globals.EXCEPTION_KEY?
Sanjay Virkar

Joined: Apr 03, 2005
Posts: 19
any help here?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The code you've shown is is simply not the right way to display an exception in an error page.

The default behavior of the Struts exception handler is to create an ActionErrors object containing an ActionMessage with the key you specified. All you have to do to display the error is use either the <html:errors /> tag or a combination of <html:messages> and <bean:write>. If you want to display the error message from the thrown exception, just place a {0} in your message text, and Struts will substitute the error message there. Example:

Then in your JSP:

If you want more formatting options, use <html:messages> instead. Example:

[ June 07, 2007: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link:
subject: Globals.EXCEPTION_KEY
It's not a secret anymore!