获取session的几种方法

获取session常用的几种方法

1.spring mvc中

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();


2. struts2中

(1)

ActionContext context = ActionContext.getContext(); 
Map request = (Map) context.get("request"); 
Map session = context.getSession(); 
Map application = context.getApplication(); 


(2)

ActionContext actionContext = ActionContext.getContext(); 
HttpServletRequest request = (HttpServletRequest) actionContext
.get(ServletActionContext.HTTP_REQUEST); 
HttpSession session = request.getSession(); 
ServletContext context = (ServletContext) actionContext 
 .get(ServletActionContext.SERVLET_CONTEXT); 


3.通过ServletActionContext获取

   HttpServletRequest request = ServletActionContext.getRequest(); 
   HttpSession session = request.getSession(); 



你可能感兴趣的:(JAVA后台,JAVA工具类)