Struts2 validation. xml verification rule code parsing,

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.