Tutorials : Handling Messages, Errors and Exceptions in Struts 1.1 :

The old ActionError(s)

If you've been using Struts before version 1.1 you probably know the ActionErrors and ActionError classes and the corresponding <html:errors> tag. The new ActionMessages and ActionMessage classes and <html:messages> tag are meant to replace these. The reason is that the <html:errors> tag forced you to place HTML in the message resource file, which is not nice. This is not necessary with the new <html:messages> tag, since it sets up a loop where you may easily stick in the HTML you want. The name ActionError(s) is also misleading, since they're not only supposed to hold an error message, but, rather, any message.

Struts, however, maintains two separate queues: one for ActionErrors and one for ActionMessages. They're both held in the request object:

Collection Queue name in request object Saved by
ActionErrors Globals.ERROR_KEY =
"org.apache.struts.action.
ERROR"
saveErrors
(HttpServletRequest request, ActionErrors errors)
ActionMessages Globals.MESSAGE_KEY =
"org.apache.struts.action.
ACTION_MESSAGE"
saveMessages
(HttpServletRequest request, ActionMessages messages)

The plan is that in some coming Struts release--maybe 1.2--the ActionError(s) classes will be deprecated. My advice is therefore that you use the new ActionMessage(s) classes. There is one issue however in doing this. The Validator that was introduced in Struts 1.1 still uses the ActionErrors class. The same goes for the validate method in the ActionForm class. 

To display messages from the ActionErrors object you may use this tag:

<html:messages id="msg" message="false">
<bean:write name="msg"/><br>
</html:messages>

It's optional to specify message="false".

Earlier we saw that messages from the ActionMessages object are displayed like this:

<html:messages id="msg" message="true">
<bean:write name="msg"/><br>
</html:messages>

My best advice--until version 1.2 comes out and clarifies things--is this: use ActionErrors for validations, and ActionMessages for all other messages. For showing all the messages you'll unfortunately have to use both of the tags above.

Recap (1)

To have a message displayed in the browser, you first use the ActionMessage(s) classes for storing message data. You typically do this in the Action class. In the jsp-page you use the <html:message> tag to display one or more of the messages.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.