public class UserAction extends ActionSupport { private String password; pirvate String name; //……对应的setter,getter方法 public void execeute() { System.out.println(name +”:”+passowrd); return “success”; } }相应提交方式可以用get和post,如:userAction?password=admin&name=admin
public class UserAction extends ActionSupport { private User user; //……对应的setter,getter方法 public void execeute() { System.out.println(user.getName() +”:”+user.getPassowrd()); return “success”; } }
public class UserDTO { private String name; private String password; private String confirm; //……对应的setter,getter方法 }可能的Action
public class UserAction extends ActionSupport { private UserDTO user; //……对应的setter,getter方法 public void execeute() { if(checkdate(userDTO userDTO) )//检查数据{ newUser(UserDTO userDTO)//创建User对象 System.out.println(user.name +”:”+user.passowrd); return “success”; } return “fail”; } }提交参数的方式的Domail Model方式的相同。
public class UserAction extends ActionSupport implements ModelDriven<User> { private User user = new User(); // 这里要手动的New下 // ……对应的setter,getter方法 public void execeute() { System.out.println(user.name +”:”+user.passowrd); return “success”; } public User getModel() { return user; } }前两种方法比较常用
相应提交方式可以用get和post,如:userAction?password=admin&name=admin
<package name="test" namespace="/test" extends="struts-default"> <action name="helloworld" > <param name="savePath">/images</param> <result name="success">/WEB-INF/page/hello.jsp</result> </action> </package>上面通过<param>节点为action的savePath属性注入“/images”