一、在action中直接写页面传递的属性来接受
action
1 public class UserAction extends ActionSupport {
2
3 private String name;
4 private int age;
5
6 public String add() {
7 System.out.println("name=" + name);
8 System.out.println("age=" + age);
9 return SUCCESS;
10 }
11
12 public String getName() {
13 return name;
14 }
15
16 public void setName(String name) {
17 this.name = name;
18 }
19
20 public int getAge() {
21 return age;
22 }
23
24 public void setAge(int age) {
25 this.age = age;
26 }
27
28
29 }
页面传递参数为name与age如:<a href="user/user!add?name=a&age=8">添加用户</a>
二、使用DomainModel接受参数
action
1 public class UserAction extends ActionSupport {
2
3 private User user;
4 //private UserDTO userDTO;
5 public String add() {
6 System.out.println("name=" + user.getName());
7 System.out.println("age=" + user.getAge());
8 return SUCCESS;
9 }
10
11 public User getUser() {
12 return user;
13 }
14
15 public void setUser(User user) {
16 this.user = user;
17 }
18 }
domain
1 public class User {
2 private String name;
3 private int age;
4 public String getName() {
5 return name;
6 }
7 public void setName(String name) {
8 this.name = name;
9 }
10 public int getAge() {
11 return age;
12 }
13 public void setAge(int age) {
14 this.age = age;
15 }
16 }
页面传递参数是需要这样来传递如:
<a href="user/user!add?user.name=a&user.age=8">添加用户</a>