Verification with Actionsupport implementation

Source: Internet
Author: User

The first type:

As long as the action class inherits the Actionsupport, you can use the validation scheme.

It's a primitive solution, it needs to write code, but it's very flexible, login case

Insufficient: The code for Business processing and validation is mixed together, which makes it inconvenient to verify the reuse and maintenance of the part

@Overridepublic String Execute () throws Exception {User user=userservice.getuser (loginName), if (user==null) {  Addfielderror("LoginName", GetText ("Invalid.loginname"));//correspondence <s:fielderror/>//Display field-related error messages

//addactionerror corresponds to <s:actionerror/> displays all information about the action return input;//indicates the need to re-enter}else if (! User.getpassword (). Equals (password)) {addfielderror ("password", GetText ("Invalid.password")); return INPUT;} Else{sessionmap.put ("user", user); return SUCCESS;}}

The second type:

Overriding the Validate () method

Business and data separation

Insufficient: Before the business method is called, when the Validate () method validation does not pass, then the validation method of the action class will not be executed, that is, validate () also tube action all validation, if you want to validate a single business method is not

The third type:

Vlidatexxx () validation

Xxx () is written to be specific to a particular method

Verification with Actionsupport implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.