STRUTS2 Custom Claim Validator

Source: Internet
Author: User

1//Create a new validators.xml under the SRC root resource, it will cover the default.xml validators, so you know
Then, if you use declarative validation, you put the configuration file Xxxaction-validation.xml in the same directory as the action class.
  
   //See Default.xml Source code, find a validator class look inside the wording, found that inherit this class can
2 Public classMyvalidatorsextendsFieldvalidatorsupport {3 4 //object representing the action class of the checksum5 Public voidValidate (Object object)throwsvalidationexception {6 //TODO auto-generated Method Stub7 //Get field name8String FieldName =getfieldname ();9 TenString value = (string) This. GetFieldValue (FieldName, object); - //if (value = = null) { - //Addfielderror (FieldName, object); the // } - //If the value is not empty then the business logic can continue - if(Stringutils.isnotempty (value)) { - //This.addfielderror (Value, object); + - //If the password strength is weak, the check does not pass + if(!Validatepass (value)) {
There is no need to write error messages, because the error message is specified in the XML configuration file, and the declarative validation in message writes the error message A This. Addfielderror (FieldName, object); at } - } - } - - //The following is the verification of password strength - Private Static FinalString GROUP1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; in Private Static FinalString GROUP2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - Private Static FinalString GROUP3 = "0123456789"; to protected BooleanValidatepass (String password) { + BooleanOk1 =false;//has a lowercase letter of true - BooleanOk2 =false;//has a capital letter of True the BooleanOK3 =false;//There is a number that is true * intLength =password.length (); $ for(inti=0;i<length;i++){Panax Notoginseng if(ok1&&ok2&&ok3) - Break; theString character = password.substring (i,i+1); + if(Group1.contains (character)) { AOk1 =true; the Continue; + } - if(Group2.contains (character)) { $Ok2 =true; $ Continue; - } - if(Group3.contains (character)) { theOK3 =true; - Continue;Wuyi } the } - returnok1&&ok2&&Ok3; Wu } -}



STRUTS2 Custom Claim Validator

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.