struts2开发action 的三种方法
1、继承ActionSupport
public class UserAction extends ActionSupport { // Action中业务处理方法 public String login() { System.out.println("UserAction.login()"); // return "success"; return SUCCESS; } }
2、实现Action
public class UserAction3 implements Action { // Action中业务处理方法 public String login() { System.out.println("UserAction.login()"); return "success"; } @Override public String execute() throws Exception { return null; } }
3、既不继承也不实现任何的方法
public class UserAction { private String userName; public void setUserName(String userName) { this.userName = userName; } // Action中业务处理方法 public String login() { System.out.println("UserAction.login()" + userName); return "login"; } public String register() { System.out.println("register()" + userName); return "register"; } }
动态方法调用
时间: 2024-10-11 08:19:52