aspose file tools*
The moose likes Struts and the fly likes How to display the error msg matching the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to display the error msg matching the "key" of "exception" tag ?" Watch "How to display the error msg matching the "key" of "exception" tag ?" New topic
Author

How to display the error msg matching the "key" of "exception" tag ?

Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
in struts-config.xml, I have

<exception key="io.error" path="/errors.jsp" scope="request"
type="java.io.IOException" />

in "ApplicationResource.properties" I have

io.error=<P>This is an IO error</P>

Now once an IOException occurs, I am wondering what I should write in "errors.jsp" to display that "THis is an IO error" ? It may be easy for some of you, but I just don't know. never done it. I tried adding a <html:errors/> in it but it doesn't grab that line. What if I want to display that line plus getting more exception information ? Any help will be appreciated.

thanks.
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
still have no clue on this. Should I use some "message" kind tag to do it ? What I tried is to put <html:errors/> in the generalerror.jsp and it does show the specific Exception type but it does NOT display what I put in the ApplicationREsources.properties file. Any idea ?
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
Do your methods all pass the exceptions on up, or handle them? Make sure that this exception is not being caught anywhere else in your code.

Steve
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
Originally posted by Steve McCann:
Do your methods all pass the exceptions on up, or handle them? Make sure that this exception is not being caught anywhere else in your code.

Steve


my methods pass those exceptions on.
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
Is it true that only for "handled" exception we can use the error key stored in ApplicationResources.properties ? If it is handled by us, we can use "ActionMessage" to add the error and then the error will be displayed based on its "key" entry in the properties file. If the error is not handled and just thrown all the way up, I guess whatever I put in the ApplicationResource.properties will not be used at all. The system will the msg in its own way. Is my understanding correct ?
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
we can use "ActionMessage" to add the error and then the error will be displayed based on its "key" entry in the properties file.

As I understand things, you can use the ActionMessage class to get any messages in the ApplicationResources.properites file - not just for Exceptions.

in struts-config.xml, I have

<exception key="io.error" path="/errors.jsp" scope="request"
type="java.io.IOException" />

You don't say where in the struts-config.xml you have placed this exception.
The <exception> tag must be within either <action> or <global-exceptions>. If inside <action> then this exception will be picked up and handled by only the specific Action. Try moving it into the <global-exceptions>.
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
Originally posted by Steve McCann:

You don't say where in the struts-config.xml you have placed this exception.
The <exception> tag must be within either <action> or <global-exceptions>. If inside <action> then this exception will be picked up and handled by only the specific Action. Try moving it into the <global-exceptions>.


Thanks. Actually I do put it in <global-exception>. What stopped me is what to write in the error.jsp page to display that particular type error's ms defined in the .properties file. You mentioned using ActionMessage. Could you show me a very simple example of how ?

Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Just put the tag:

<html:errors/>

in your JSP. Struts will automatically populate it with the error message when it forwards to the JSP.


Merrill
Consultant, Sima Solutions
Artemesia Lakener
Ranch Hand

Joined: Jun 21, 2005
Posts: 162
Originally posted by Merrill Higginson:
Just put the tag:

<html:errors/>

in your JSP. Struts will automatically populate it with the error message when it forwards to the JSP.


that's what I have tried. It does show the type of exception but it does *not* explicitly display that "This is an IO error" String indicated in the properties file

ApplicationResource.properties:

**
error.io=<P>This is an IO error</P>
...
...
***

I want the page display that String I put.
Daniel Cardenas
Greenhorn

Joined: Jul 26, 2005
Posts: 10
hi everyone.
i'm interested in how to resolve your problem about:
'How to display the error msg matching the "key" of "exception" tag'

if you prefer, you can send me an email: danielkard@gmail.com
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Hi,

Try to put scope="session" instead of scope="request".
Maybe it's working better...
[ July 27, 2005: Message edited by: Cendy Nguvy ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display the error msg matching the "key" of "exception" tag ?