Struts2--Action属性接收参数
1. JSP文件调用格式:
<a href="user/user!add?name=a&age=8">添加用户</a>
2. struts.xml文件:
<package name="user" extends="struts-default" namespace="/user"> <action name="user" class="com.bjsxt.struts2.user.action.UserAction"> <result>/user_add_success.jsp</result> </action> </package>
3. action文件:和jsp传递过来的name和age一一对应传值进去
package com.bjsxt.struts2.user.action; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private String name; private int age; public String add() { System.out.println("name=" + name); System.out.println("age=" + 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; } }