01_9_Struts用ModelDriven接收参数
1. 配置struts.xml文件
<package name="user" namespace="/user" extends="struts-default">
<action name="user" class="com.sumapay.user.UserAction">
<result name="add">
/AddUser.jsp
</result>
<result name="success">
/AddUserSuccess.jsp
</result>
</action>
</package>
2. 创建Action类
package com.sumapay.user;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sumapay.domain.User;
public class UserAction extends ActionSupport implements ModelDriven<User> {
private static final long serialVersionUID = 1L;
private User user = new User();;
public String add() {
return "add";
}
public String execute() {
System.out.println("name: " + user.getName());
System.out.println("age: " + user.getAge());
return "success";
}
@Override
public User getModel() {
return user;
}
}
3. 传递参数
http://127.0.0.1:8080/struts/user/user?name=fengge124&age=31