struts2中action的新手问题
<action name="login*" class="com.bjsxt.struts2.user.action.LoginAction{1}">
<result>/user_login_success.jsp</result>
</action>
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction1 extends ActionSupport {
private Map request;
private Map session;
private Map application;
public LoginAction1() {
request = (Map)ActionContext.getContext().get("request");
session = ActionContext.getContext().getSession();
application = ActionContext.getContext().getApplication();
}
public String execute() {
request.put("r1", "r1");
session.put("s1", "s1");
application.put("a1", "a1");
return SUCCESS;
}
}
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
private String name;
public String add() {
System.out.println("name=" + name);
return SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
[解决办法]
拿你 name属性来说,action被方法的时候 默认调用set方法,获取从页面传来的值 调用方法完毕调用get方法吧值传递到页面去 个人理解是 set = getParameter() get = setAttribute()