1.通过属性传参数
public class UserAction extends ActionSupport {
private String name;
private int age;
public String add() {
<span style="white-space:pre"> </span>return SUCCESS;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
}
调用方法:actionName.action?name=123&age=22
2.通过域模型传参数
public class UserAction extends ActionSupport {
private User user;
public String add() {
<span> </span>return SUCCESS;
}
public int get<span style="font-family: Arial, Helvetica, sans-serif;">User</span><span style="font-family: Arial, Helvetica, sans-serif;">() {</span>
return <span style="font-family: Arial, Helvetica, sans-serif;">user</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span>
}
public void setUser(User user) {
this.user = user;
}
}
public class User()
{
<div style="orphans: auto; text-align: start; widows: auto;"> <span>private<span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"> String name;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>private int age;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);">
</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>public void setName(String name)</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>{</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>this.name=name;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>}</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>public void setAge(int age)</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>{</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>this.age=age;</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>}<span style="white-space:pre"> </span></span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>public String getName()</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>{<span style="white-space:pre"> </span></span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="white-space:pre"> </span>r</span>eturn this.name;</div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>}</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>public int getAge()</span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>{<span style="white-space:pre"> </span></span></span></div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="white-space:pre"> </span>r</span>eturn this.age;</div><div style="orphans: auto; text-align: start; widows: auto;"><span><span style="font-family: Verdana, Helvetica, Arial; line-height: 22.75px; font-size: 13px; orphans: 2; text-align: justify; widows: 2; background-color: rgb(238, 238, 238);"><span style="white-space:pre"> </span>}</span></span></div>
}
调用方法:actionName.action?user.name=123&user.age=22
3.通过模型驱动传参数(Model Driven)
public class UserAction extends ActionSupport implements ModelDriven<User> {
private User user = new User();
public String add() {
System.out.println("name:"+user.getName());
System.out.println("age:"+user.getAge());
return SUCCESS;
}
@Override
public User getModel()
{
return user;
}
}
调用方法:actionName.action?name=123&age=22