After Struts 1.1, the preferred way to handle errors in your Java code is:
and to display those messages in the JSP:
or if you are not using the struts-el tags:
This change was motivated by the realization that there are non-error messages that need to be communicated. Action now has an additional method saveMessages(request,ActionMessages), which saves the messages in request scope under a different key, Globals.MESSAGE_KEY. To display messages saved with saveMessages:
Finally, you can save an ActionMessages object under an arbitrary key and display it with the html:messages tag:
and in your page:
Of course, see the full html:messages doc for details.
Response: use ActionMessages anywhere except in an ActionForm. Soon we will provide an alternate method on ActionForm which returns an ActionMessages and lets us move forward with fully deprecating ActionErrors.
Comment from Niall Pemberton: ''This page implies that the <html:messages> tag is the preferred way to handle messages - I don't agree with that. Wether you use <html:messages> or <html:errors> is just a matter of preference - see here for a comparison.