Structs implementation of three actions

Source: Internet
Author: User

Structs implementation of three actions

First: a general class with the public String execute () method.

Type 2: class that inherits the LoginActionInterface implements Action interface.

Class 3: class that inherits the abstract class of LoginActionSupport extends ActionSupport.


Structure chart



The three classes are also posted for your reference.

Package com. test. action; import com. test. dao. userCheck; import com. test. vo. user; public class LoginAction {private String username; public String getUsername () {return username;} public void setUsername (String username) {this. username = username;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;} private String password; public String execute () {User u = new User (); u. setUsername (this. getUsername (); u. setPassword (this. getPassword ();/* call the business logic layer Code */UserCheck check = new UserCheck (); if (check. login (u) {return "login_ OK";} else {return "login_fail ";}}}

Package com. test. action; import com. opensymphony. xwork2.Action; import com. test. dao. userCheck; import com. test. vo. user; public class LoginActionInterface implements Action {private String username; public String getUsername () {return username;} public void setUsername (String username) {this. username = username;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;} private String password; public String execute () {User u = new User (); u. setUsername (this. getUsername (); u. setPassword (this. getPassword ();/* call the business logic layer Code */UserCheck check = new UserCheck (); if (check. login (u) {return "login_ OK";} else {return "login_fail ";}}}

Package com. test. action; import com. opensymphony. xwork2.ActionSupport; import com. test. dao. userCheck; import com. test. vo. user; public class LoginActionSupport extends ActionSupport {/*****/private static final long serialVersionUID = 1L; public LoginActionSupport () {System. out. println ("LoginActionSupport");} private String username; public String getUsername () {return username;} public void setUsername (String username) {this. username = username;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;} private String password; public String execute () {User u = new User (); u. setUsername (this. getUsername (); u. setPassword (this. getPassword ();/* call the business logic layer Code */UserCheck check = new UserCheck (); if (check. login (u) {return "login_ OK";} else {return "login_fail ";}}}


In fact, we found that as long as there is a public String execute () method, but also note that when inheriting ActionSupport, the default execute () is to return success.

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.