Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Globals.EXCEPTION_KEY

 
Sanjay Virkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any help here?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic