It represents all messages in the Actionmessages object that is stored in the "org.apache.struts.Globals.ERROR_KEY" keyword in the output request or session scope.
You can output the specified message by setting the following properties.
Name property: Specifies a keyword within the scope of the request or session that specifies a Actionmessages object. If this property is omitted, the default keyword is "org.apache.struts.Globals." Error_key ".
Property attribute: Used to specify a message property in the Actionmessages object specified by the keyword specified by the Name property, which specifies a Actionmessage object. If this property is omitted, the
Bundle Property: Specifies the message resource file. If this property is omitted, the message contents of the output are obtained from the default message resource file Applicationresources.properties.
The label is similar to the 1. The same point as the
The source:
Actionmessage messages=new actionmessages ();
Errors.add ("username", New Actionmessage ("Com.logon.name.error"));
Saveerrors (request,messages);
Property:2. Different points from
Property
The Message property,
The ID property, which is a property that must exist for the
How to: Use
Description The:<bean:write> label is used to output the object value specified by the Name property. Please refer to chapter 8th of this book for a detailed introduction.
The code that uses the
<bean:write name= "MessageID"/>
The Saveerrors (request,errors) method saves the Actionmessages object to the request scope and is stored in the "org.apache.struts.Globals.ERROR_KEY" keyword. The key code for the Saveerrors () method in the action base class is as follows.
protected void Saveerrors (HttpServletRequest request, actionmessages errors) {
Request.setattribute (org.apache.struts.globals.error_key,errors);
}
Messages that display related errors can be displayed on the page by
Or
<bean:write name= "Error"/>
To fetch a single error message for property= "Nameempty" (Note: ID is only a mark, as long as it is consistent with the Bean:write Name property)
----------------------------------------
Or
<bean:write name= "Error"/>
To fetch all the error messages.
Equivalent
In addition, you can save the Actionmessages object to the request scope through the Savemessages (request,errors) method, but at this point in the request scope, " Org.apache.struts.Globals.MESSAGE_KEY "Keyword storage. The key code for the Savemessages () method in the action base class is as follows.
protected void Savemessages (HttpServletRequest request, actionmessages errors) {
Request.setattribute (org.apache.struts.globals.message_key,errors);
}
So if you use the Savemessages () method to store the message, you specify "Org.apache.struts" in the request or session scope by using the Name property when you use the
<bean:write name= "Error"/>
Or
<bean:write name= "Error"/>
To fetch all or a single error message, respectively
Note the point:
Although Struts has stated that it is not recommended to use Actionerrors & Actionerror objects, the shadow is still visible in some legacy systems, so if your system unfortunately belongs to two hybrid systems, there are several ways to refer to
1. Two times call Messagespresent, as follows
<!--Print Actionerrors Object-->
<logic:messagesPresent>
<div class= "Success" >
<bean:write name= "msg"/>
</div><br/>
</logic:messagesPresent>
<!--Print Actionmessages Object-->
<logic:messagespresent message= "true" >
<div class= "Success" >
<bean:write name= "msg"/>
</div><br/>
</logic:messagesPresent>
2. The use of
3. Replace all actionerrors for actionmessages, and replace all calls Saveerrors to Savemessages and replace the