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:
In
Four types of methods
1. Verify configuration with JavaScript: Write
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
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