0%
使用Action的属性接收参数
1 2 3 4 5 6
| <form action="myAction" method="post"> <input type="text" name="username"/> <input type="password" name="password" /> <input type="submit" value="提交" /> </form>
|
1 2 3 4 5 6 7 8 9
| public class MyAction extends ActionSupport{ private String username; private String password; public String execute() throws Exception{ System.out.println(getUsername()+":"+getPassword()); return SUCCESS; } }
|
使用Domain Model接收参数
1 2 3 4 5 6
| <form action="myAction" method="post"> <input type="text" name="user.username"/> <input type="password" name="user.password" /> <input type="submit" value="提交" /> </form>
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class User{ private String username; private String password; } public class MyAction extends ActionSupport{ private User user; public String execute() throws Exception{ System.out.println(user.getUsername()+":"+user.getPassword()); return SUCCESS; } }
|
实现ModelDriven接口接收参数
1 2 3 4 5 6
| <form action="myAction" method="post"> <input type="text" name="username"/> <input type="password" name="password" /> <input type="submit" value="提交" /> </form>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public class User{ private String username; private String password; } public class MyAction extends ActionSupport implements ModelDriven<User>{ private User user = new User(); public String execute() throws Exception{ System.out.println(user.getUsername()+":"+user.getPassword()); return SUCCESS; } public User getModel(){ return user; } }
|