论坛首页 入门技术论坛

在struts2中获得Session的方法

浏览 5544 次
该帖已经被评为新手帖
作者 正文
   发表时间:2011-02-27   最后修改:2011-03-01

 

一:实现implements SessionAware接口 

 

 

 

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

 

 

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

session.put("user", user);

 

 

 

 


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

ServletActionContext.getRequest().getSession();//这个是HttpSession形式的
多谢广大网友的支持,如果你还有新的方法,请分享一下,供大家学习
   发表时间:2011-02-28  
ActionContext.getContext().getSession();//这个是Map形式的

ServletActionContext.getRequest().getSession();//这个是HttpSession形式的
0 请登录后投票
   发表时间:2011-02-28  
引用

Map request = (Map) ActionContext.getContext().getSession();
request.put("user", user);


好吧,我对这命名方式表示不那么淡定了。
明明session,尽管不是HttpSession,但好歹不要命名成request吧。。。
0 请登录后投票
   发表时间:2011-02-28  
kongzhizhen 写道
引用

Map request = (Map) ActionContext.getContext().getSession();
request.put("user", user);


好吧,我对这命名方式表示不那么淡定了。
明明session,尽管不是HttpSession,但好歹不要命名成request吧。。。

哈哈 忘记改了
0 请登录后投票
   发表时间:2011-02-28  
顶松哥!话说  你这命名的确不让人淡定...整个清楚明白的呗!
0 请登录后投票
   发表时间:2011-02-28  
嗯 那我再整理下
0 请登录后投票
   发表时间:2011-02-28  
别忘了这一种getSession(boolean create)
0 请登录后投票
   发表时间:2011-02-28  
谢谢 指导
0 请登录后投票
   发表时间:2011-02-28  
非常好 ,谢谢指点
0 请登录后投票
   发表时间:2011-03-01  
ServletActionContext.getRequest().getSession();
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics