• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just put the tag:

<html:errors/>

in your JSP. Struts will automatically populate it with the error message when it forwards to the JSP.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Try to put scope="session" instead of scope="request".
Maybe it's working better...
[ July 27, 2005: Message edited by: Cendy Nguvy ]
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic