Struts2 validation. xml verification rule code parsing,
When using the validation. xml of struts2 for verification, pay attention to the following aspects:
I. First, pay attention to the validation. xml name. You must add "-validation. xml" to the Action class name as the file name. Into the LoginAction-validation.xml.
II. The LoginAction-validation.xml file must be in the same directory as the Action class.
III. The type attribute of the <field-validator type = ""> tag in the validation. xml file must be the same as the data type of the attribute defined in VO.
IV. in struts. the <action> label in the xml file must contain <result name = "input"> and <result name = "success">. Otherwise, the page (404) cannot be found ).
V. A sample validation. xml code:
<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE validators PUBLIC "-// OpenSymphony Group // XWork Validator 1.0.2/EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <field name = "user. strUsername"> <! -- The verification string cannot be blank --> <field-validator type = "requiredstring"> <! -- Remove space --> <param name = "trim"> true </param> <! -- Error message --> <message> User name cannot be blank </message> </field-validator> <! -- Verify the string length --> <field-validator type = "stringlength"> <param name = "minLength"> 2 </param> <param name = "maxLength"> 20 </ param> <message> the user name must be 2 to 18 characters in length </message> </field-validator> </field> <field name = "user. strPassword "> <field-validator type =" requiredstring "> <param name =" trim "> true </param> <message> the password cannot be blank </message> </field -validator> <field-validator type = "stringlength"> <param name = "minLength"> 6 </pa Ram> <param name = "maxLength"> 18 </param> <message> the password must be between 6 and 18 characters </message> </field-validator> </ field> <! -- <Field name = "user. age "> <field-validator type =" int "> <param name =" min "> 1 </param> <param name =" max "> 150 </param> <message> the age must be between 1 and 150. </message> </field-validator> </field> the verification string is of the date type. <field name = "user. birthday "> <field-validator type =" date "> <param name =" min "> </param> <param name =" max "> </param> <message> the birth date should be between and </message> </field-validator> </field> --> </validators>
Summary
The above is all the content about struts2 validation. xml verification rule code parsing. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!