wood burning stoves 2.0*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts html:errors tag and JSP" Watch "Struts html:errors tag and JSP" New topic

Struts html:errors tag and JSP

Mohammed Safi

Joined: Aug 07, 2002
Posts: 2
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.
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}


Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60785

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.
[ August 08, 2002: Message edited by: Bear Bibeault ]

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

Joined: Jan 10, 2002
Posts: 60785

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.
[ 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
Similar Threads
HFSJ struts Example pgm
Show Struts error in JSP
Getting Message from properties file in servlet
How to display the error msg matching the "key" of "exception" tag ?
validation.xml - how to ignore the required fields if a checkBox was clicked?