Both of these methods are methods implemented by the Actionsupport class, and in the application we will inherit the Actionsupport class, implementing a HasErrors () method in the Actionsupport class that will determine if there are two levels ( Action and field level), so when we need to make an error, we can apply it conveniently:
try {
Xxx
} catch (Exception e) {
Super.addfielderror ("username", "input error");
Or:
Super.addactionerror ("incorrect input");
}
Interested can study the source code, when used we only need to display these errors on the page OK.
Such as:
<s:fielderror>
<s:param>username</s:param>
</s:fielderror>
Or
<s:actionerror/>
But in practice, fielderror we tend to have a targeted error message output, because Fielderror itself is a map that can specify the wrong field in detail-the reason. And it is more appropriate when the form is submitted, as long as the field that corresponds to the error field and the submission property. STRUTS2 will automatically format the table for us (no test)
Modified topic: <s:form theme= "Simple" > can not display error messages, cannot automatically add table layout, as needed to play
Note: We only need to set Error the default input , Struts2 will automatically do the view forwarding for us, <result name= "input" >/input.jsp</result>
Struts2 Two classic methods for validating error messages-addfielderror&addactionerror