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