Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts html:errors tag and JSP

 
Mohammed Safi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic