01_7_Struts_用Action的属性接收参数

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

posted @ 2018-03-25 23:11  FlyBack  阅读(117)  评论(0编辑  收藏  举报