sturts2在action中session的存入、取出、清空

//首先需要导入包
//action 内处理 session 需要导入的类
import com.opensymphony.xwork2.ActionContext;

session
//方法一:
public class SessionContext {

public static final String GLOBLE_USER_SESSION = "globle_user";  

public static void setUser(Employee user){  
    if(user!=null){  
        ServletActionContext.getRequest().getSession().setAttribute(GLOBLE_USER_SESSION, user);  
    }else{  
        ServletActionContext.getRequest().getSession().removeAttribute(GLOBLE_USER_SESSION);  
    }  
}  

public static Employee get(){  
    return (Employee) ServletActionContext.getRequest().getSession().getAttribute(GLOBLE_USER_SESSION);  
}  

}

//方法二:
// 创建 ActionContext
ActionContext actionContext = ActionContext.getContext();
Map

猜你喜欢

转载自blog.csdn.net/wyf871125/article/details/80359871