package com.lsp.action; import com.opensymphony.xwork2.ActionSupport; /** * ----------------这里是Action添加成员属性接受参数-------------- */ public class Action1 extends ActionSupport { private int id; private String name; public String test1() { System.out.println("name" + name); System.out.println("id" + id); return "test1"; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
=====================================================================================
package com.lsp.action; import com.lsp.entity.User; import com.opensymphony.xwork2.ActionSupport; /** *利用对象域来进行传递和接受参数 */ public class Action2 extends ActionSupport { private User user; public String test2() { System.out.println("name=" + user.getName()); System.out.println("id+" + user.getId()); return "test2"; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } }
=======================================================================
package com.lsp.action; import com.lsp.entity.User; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; /** *域模型 */ public class Action3 extends ActionSupport implements ModelDriven<User> { private User user = new User(); public String test3() { System.out.println("name=" + user.getName()); System.out.println("id=" + user.getId()); return "tset3"; } @Override public User getModel() { // TODO Auto-generated method stub return user; } }
可参考博客:http://www.cnblogs.com/bukudekong/archive/2012/03/29/2423064.html