aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Globals.EXCEPTION_KEY" Watch "Globals.EXCEPTION_KEY" New topic
Author

Globals.EXCEPTION_KEY

Sanjay Virkar
Greenhorn

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.
<global-exceptions>
<exception bundle="ApplicationResources"
key="error.db.sql"
type="java.sql.DbException"
path="/WEB-INF/jsp/errorpg.jsp" >
</exception>
<exception bundle="ApplicationResources"
key="error.db.noconnection"
type="com.NoDbConnection"
path="/WEB-INF/jsp/errorpg.jsp" >
</exception>
</global-exceptions>

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

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

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
Greenhorn

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 ]

Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Globals.EXCEPTION_KEY