Validator page verification in Struts

xiaoxiao2021-03-06  95

Validator page verification in Struts

Ugly && Snowtears

After 2 weeks of unremitting efforts, a lot of information was read, and finally had a preliminary understanding of Validator, sorted out, talking about talking about writing, hoping to have certain help, where there is certainly not right Accurate place, please advise real_herozx@163.net

First, write in the struts-config.xml file:

The part of xxx.xxxx.xxxx is the path to the resource file < Set-property value = "/ web-inf / validator-rules.xml, / web-inf / value) /> Here if you want to use multiple ***. If the XML file, the Value part is written as shown below value = "/ Web-inf / validator-rules.xml, / web-inf / validation.xml, /web-inf/Validation1.xml, /web-inf/validation2.xml"

In , you should add Validate = "true" when defining the action that needs to be verified.

Four types of methods

1. Verify configuration with JavaScript: Write to write to the verification code in the validation.xml file. You can make basic validation. For details, please refer to http://www.chinajavaworld.net/forum/topic.cgi?forum=48&topic=1413&show=50

This method is to verify at the client, and the client can see the entire code of the JavaScript section. Safety is not high. Make your ActionForm inherit the ValidatorForm class, write your own method inside: public actionerrors validate (actionmapping mapping, httpservletRequest request) {

ActionerroS Errors = new actionerrors ();

. . . . . . IF (MyText.Equals ("AAA")) {// my example ire errors.add ("mytext", new actionerror ("mytext.error");}. . . . . . Return Errors;

} At this time, if this method is written, it will block the verification section defined in validation.xml. In other words, the system is running, and the defined error verification part of this ActionForm in Validation.xml does not practice if not written If this method, the system is running in validation.xml to operate the definition of this ActionForm, which is verified by the server side, and the authentication part code client is not visible.

3. Dynamic Verification DynavalidatorForm does not need to write the corresponding ActionForm, simply configuring its ActionForm in struts-config.xml Set the corresponding project in Form-property, such as MyText, MytextArea, how often, when executed, the actionform is written in validation.xml The desired verification code can be

There is no need to write anything in the JSP file. Verification is also on the server side, verify that some code is invisible in JSP.

4. Combination verification If you use dynamic verification DynavalidatorForm, you don't write your own corresponding ActionForm, and the corresponding special verification will be considered a considerable limit.

At this time, you need to write a special verification section to the corresponding action.

IF (MyText.Equals ("AAA")) {// my exampleErrors errors = new actionerror (); errors.add ("***", new actionerror ("***. error"); SaveErrors (Request, Errors); return ("false"));} can achieve special verification

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

New Post(0)