I. Analysis of struts2 declarative verification principles
1. struts2 provides a validation interceptor in the default interceptor stack, which is responsible for loading and executing registered verification programs.
The running sequence diagram is as follows:
2. Each validation rule corresponds to a specific validator. a configuration file associates the verification rule name with the validator. In fact, the validator is executed.
The file is located in default. xml under com. opensymphony. xwork2.validator. validators.
As shown in:
3. the correspondence between the configuration file and the validator property, as shown in:
2. struts2 built-in verification program
Struts2 built-in verification program (refer to). The specific descriptions are as follows:
1) required: Make sure that the value of a given field is not null
2) requiredstring: Make sure that the value of a given field is neither null nor blank (that is, an empty string ).
-Trim parameter. The default value is true, indicating that struts removes leading and trailing spaces before verifying the field value.
3) stringlength: Verify that a non-empty field value has enough length.
-Minlength: minimum length of the related field. If this parameter is not provided, this field will not have the minimum length limit.
-Maxlength: the maximum length of the related field. If this parameter is not provided, this field does not have the maximum length limit.
-Trim: whether to remove leading and trailing spaces before verification
4) Date: Make sure that the value of a given date field falls within a given range.
-Max: maximum value of the related field. If this parameter is not provided, this field has no maximum value limit.
-Min: the minimum value of the related field. If this parameter is not provided, this field has no minimum value limit.
5) Email: Check whether the given string value is a valid email.
6) URL: Check whether the given string value is a valid URL.
7) RegEx: checks whether the value of a given field matches a given regular expression pattern.
-Expresssion *: the regular expression used for matching.
-Casesensitive: whether to distinguish between uppercase and lowercase letters. The default value is true.
-Trim: whether to remove leading and trailing spaces. The default value is true.
8) int: Check whether the value of the given integer field is within a certain range.
-Min: the minimum value of the related field. If this parameter is not provided, this field has no minimum value limit.
-Max: maximum value of the related field. If this parameter is not provided, this field has no maximum value limit.
9) Conversion: Check whether the type conversion for a given action attribute will lead to a conversion error. The validators can also add a custom message based on the default type conversion message.
10) expression and fieldexpression: used to verify whether a given field meets an ognl expression.
-The former is a non-field verification program, and the latter is a field verification program.
-The former generates an action error when verification fails, while the latter generates a field error when verification fails.
-Expression *: ognl expression used for verification
Struts2 input verification (2)-declarative verification principles