File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts html:errors tag and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts html:errors tag and JSP" Watch "Struts html:errors tag and JSP" New topic
Author

Struts html:errors tag and JSP

Mohammed Safi
Greenhorn

Joined: Aug 07, 2002
Posts: 2
Hi
How do i use <html:errors> tag in my jsp. I have a LogonForm, the validate() method of the form adds ActionError to the request, Now how do i display those errors in my JSP. What all is required for that should i have a properties file with message id & message value.
What should be the name of the properties file and where it should be placed in my tomcat.
Can someone give me a example covering this subject.
thanks
safi
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

In your JSP, add a <html:errors/> tag.
The property file must be somewhere in the classpath. So I have it in /WEB-INF/classes.
Also the name of the property file must correspond
to the value specified in your web.xml servlet's
param (see parameter: application).
When you create an ActionError class, make sure you pass it a String which corresponds to a
key item in your properties file. You may optionally pass in args but that would mean that
the key entry in ApplicationResources.properties
need to look like this:
some.key = Hello {0}
Cheers,
Pho


Regards,

Pho
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

And don't forget to put values for errors.header and errors.footer in your resource file or you will get "null"s appearing on the page before and after the list of errors (if any).
The documentation that comes with Struts actually does a pretty good job of describing this.
hth,
bear
[ August 08, 2002: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

And...
If the mechanisms provided by the html:errors tag is not to your liking, it's easy to deal with the error list in your own way since the ActionErrors instance is placed in the request as an attribute with a key of Action.KEY_ERRORS.
You can retrieve this instance and use the methods on it to deal with the errors in any way that you would like.
hth,
bear
[ August 08, 2002: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts html:errors tag and JSP