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.