日期:2014-05-17 浏览次数:20832 次
//这是我获得Session的方法
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put("userid",userid)
//存放在这个Session中的值,另一个Action怎么取?
//另一个类中使用
session.get("userid");
//获得是空。
public class LoginAction3 extends ActionSupport {
//第三种取得方式
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public LoginAction3() {
request = ServletActionContext. getRequest();
session = request.getSession();
application = session.getServletContext();
}
@Override
public String execute() throws Exception {
request.setAttribute( "r1", "r1");
session.setAttribute( "s1", "s1");
application.setAttribute( "a1", "a1");
return SUCCESS;
}
}