1、struts.xml
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.i18n.encoding" value="utf-8"></constant>
<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.wxh.model.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class UserAction extends ActionSupport implements ModelDriven<User>{
private static final long serialVersionUID = 1L;
private User user=new User();
public String add(){
System.out.println("name="+user.getName());
System.out.println("age="+user.getAge());
return SUCCESS;
}
public User getModel(){
return user;
}
}
package com.wxh.model;
public class User {
private String name;
private int age;
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;
}
}
<body>
<a href="user!add?name=a">添加用户</a>
</body>