Struts uses validate

xiaoxiao2021-03-06  15

Validate uses two profiles, one is validation.xml, one is validator-rules.xml. Some purposes are described separately: 1) Validator-rules.xml: Define some universal JavaScript check rules. Note - If the tag contains a name: MSG property, the value indicating this property is defined in the resource file. For example: where msg = errors.required, found in the properties file: errors.required = {0} is required. This is implemented Dynamic information prompt for general verification rules

We can also extend this file yourself, define the verification rules we need, just refer to the format in it.

2) Validation.xml:

Specify the verification rules for the page Form form. Such as

mask ^ / w $ minlength 5 ... in the form property Name values ​​are the same as the properties of the FORMBEAN in Struts-Config.xml. The field property represents the table item. Depends indicates the verification judgment required to be required by the form. indicates the check firstname property An error message that may be displayed. Defining a school named minlength in validator-rules.xml The rule of the rules. Name = "minlength" is used below: MINL Ength 5 indicates that the value of the incoming value is 5.

3) Enable the inspection rule: Add the following 2 definitions in Struts-Config.xml. (Note: Add, different versions, refer to different TLD definitions after definitions) SAGE-RESOURES parameter = "org.apache. Struts.Webapp.validator.ApplicationResources "/>

<-! Add multiple validator resource files by setting the pathnames property with a comma delimitted list of resource files to load -.> This verification rules take effect. 4) Display error message in JSP:

In JSP page plus:


  • 5) The corresponding FORM should inherit the ValidatorForm class public final class registrationform extends ValidatorForm IMPLEments Serializable {...}

转载请注明原文地址:https://www.9cbs.com/read-67908.html

New Post(0)