Both addactionerror () and addfielderror () are methods in the com. opensymphony. xwork2.actionsupport class.
----------------------------------------------------------------------------------
1.
Addactionerror (stringAnerrormessage)
Add an action-level error message to the action
Anerrormessage: error message
The label for displaying the message is (for example, on the JSP page ):
<S: actionerror/>Display All action-level error messages. You can add CSS code.
Anerrormessage is stored in the list. You can check the source code.
----------------------------------------------------------------------------------
2.
Addfielderror (stringFieldname, stringErrormessage)
Add an error message to a field (attribute)
Fieldname: field (attribute) Name
Errormessage: error message
Errormessage is stored in a map <key, value> (the key stores fieldname, and the value stores errormessage ). You can check the source code.
The label for displaying the message is (for example, on the JSP page ):
<! -- Example 1 -->
<S: fielderror/> Display All error messages (Added using addfielderror)
<! -- Example 2 -->
<S: fielderror>
<S: param> field1 </S: param> displays the error message of the specified field1 field.
<S: param> field2 </S: param> displays error messages for the specified field2 field.
</S: fielderror>
<S: form...>... </S: Form>
------------------------------------------------------------------
Under the default topic, <s: Form/> displays the error message and automatically adds the table layout. (the error message is displayed on the top of the input text box)
Modify the topic: <s: Form theme = "simple"> the error message cannot be displayed, and the table layout cannot be automatically added.
-----------------------------------------------
The actionsupport class also has a public Boolean haserrors () method,In fact, his internal implementation is like this:
(Hasactionerrors () | hasfielderrors ())Check whether there are action-level error messages and fidld-level error messages.
If one is true, it will jump back to the input real graph and display the error message (if you write the corresponding label)