Struts Validator Framework

xiaoxiao2021-03-05  29

Framework See the frame ...

Compared to the Struts framework itself, Valida Framework is much more invasive to the code, only needs to inherit the ValidatorForm or ValidatorActionForm, which is convenient to use, you don't have to write a lot of verification code in the Form's Validate method, especially some about the input The verification of the content is more complicated. The framework can save a lot of strength, the framework provides a lot of practical verification methods, and if the verification field changes, it is generally not necessary to modify the code directly, change the frame configuration file ..... .

Less nonsense, enter the topic:

Step1) Introduced Validator Framework

In struts-config.xml (nor is it this file, maybe you have multiple profiles, but generally write in this)

In addition, you should also add in the Struts configuration file.

This is a resource file, which is installed with an error message displayed on the page.

Struts configuration file:

Step2) Prepare Validator-Rules.xml, validation.xml can easily see the framework requires two files Validator-Rules.xml, validation.xml

The former specifies the rules of the calibration, do not need you to change (unless you have to join your own verifier). This online is everywhere.

The latter is for specific applications, and in most cases you need yourself, an example below:

Validation.xml

mask ^ [1-9.] * $ mask < VAR-VALUE> ^ [AZ]

Worth with the form, name, and profile form name you want to verify, of course, you can also write to write an action path in the configuration file. The difference between the two Next section It is clearly the properties of the Form, which is the attribute name, Depends, how do you want to deliver this property, an example? Is it a for the attribute to be empty and content?

Step 3) FORM will need to be verified ValidatorForm or ValidatorActionform

The difference between these two is that the former is specifically verified for the FORM of a specific name.

Last

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

New Post(0)