1. 程式人生 > >01_7_Struts_用Action的屬性接收參數

01_7_Struts_用Action的屬性接收參數

enter ace add pan out OS rod DDU imp

01_7_Struts_Action的屬性接收參數

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;

public class UserAction extends ActionSupport {

private static final long serialVersionUID = 1L;

private String name;

private int age;

public String add() {

return "add";

}

public String execute() {

System.out.println(name);

System.out.println(age);

return "success";

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

}

3. 傳參

http://127.0.0.1:8080/Struts2_0100_Introduction/user/user!execute?name=fengge&age=31

01_7_Struts_用Action的屬性接收參數