在struts2中获得Session的方法

 

一:实现implements SessionAware接口 

 

 

 

二:调用ActionContext方法获得Session对象 代码如下:

 

 

Map session = (Map) ActionContext.getContext().getSession();

session.put("user", user);

 

 

 

 


三:调用ServletActionContext方法获得Session对象
ActionContext.getContext().getSession();//这个是Map形式的

ServletActionContext.getRequest().getSession();//这个是HttpSession形式的
多谢广大网友的支持,如果你还有新的方法,请分享一下,供大家学习

你可能感兴趣的:(struts2)