标签:style blog io ar color os 使用 sp for
1、使用属性
HTML:
<form action="login" method="post" name="form1"> 用户名:<s:textfield name="username"/><br/> 密 码:<s:password name="password"/><br/> <s:submit value="提交"/> </form>
action:
public class TestAction extends ActionSupport{ private String username; private String password; 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; } }
2、使用类来接收
HTML:
<form action="login" method="post" name="form1"> 用户名:<s:textfield name="users.username"/><br/> 密 码:<s:password name="users.password"/><br/> <s:submit value="提交"/> </form>
Action:
public class TestAction extends ActionSupport{ private Users users; public Users getUsers(){ return users; } public void setUsers(Users users){ this.users=users; }
Users类:
public class Users{ private String username; private String password; 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; } }
3、使用模型驱动
HTML:
<form action="login" method="post" name="form1"> 用户名:<s:textfield name="username"/><br/> 密 码:<s:password name="password"/><br/> <s:submit value="提交"/> </form>
Action:
public class sysAction extends ActionSupport implements ModelDriven<User>{ private User user = new User(); //必须手动实例化 public User getModel() { return user; //返回实例 } }
4、使用传统的request
public class TestAction extends ActionSupport{ private static final long serialVersionUID = -7463970150000893325L; public void execeute() { String name = super.getRequest().getParameter("paraName"); System.out.println("姓名:" + name); } }
标签:style blog io ar color os 使用 sp for
原文地址:http://www.cnblogs.com/yangzhilong/p/4163112.html