Struts2 用action属性接收参数

1、struts.xml

<struts>
 <constant name="struts.devMode" value="true" /> 
 <constant name="struts.enable.DynamicMethodInvocation" value="true" />
 <package name="user"  extends="struts-default" >                 
        <action name="user" class="com.wxh.action.UserAction" >
            <result >/useraddsuccess.jsp</result>
        </action>         
</package>     
</struts>


2、UserAction.java

package com.wxh.action;
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(){
		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;
	}
}

3、index,jsp

<body>
<a href="user!add?name=a&age=12">添加用户</a>
</body>
4 useraddsuccess.jsp

<body>
user add success
</body>





你可能感兴趣的:(struts2.0)