How do we get access to the session
You can obtain the session attributes by asking the ActionContext or implementing SessionAware. Implementing SessionAware is preferred.
1.Ask the ActionContext
The session attributes are available on the ActionContext instance, which is made available via ThreadLocal.
Map attibutes = ActionContext.getContext().getSession();
2.Implement SessionAware
Ensure that servlet-config Interceptor is included in the Action's stack.
The default stack already includes servlet-config.
Edit the Action so that it implements the SessionAware interface.
The SessionAware interface expects a setSession method. You may wish to include a companion getSession method.
At runtime, call getSession to obtain a Map representing the session attributes.
Any changes made to the session Map are reflected in the actual HttpSessionRequest. You may insert and remove session attributes as needed.
Map parameters = this.getSession();
When the servlet-config Interceptor sees that an Action implements ParameterAware, it passes a Map of the session attributes to the Action's setParameters method. Changes made to the Map are reflected in the runtime HttpSessionRequest.
1.直接使用Map attibutes = ActionContext.getContext().getSession();
2.实现SessionAware接口,然后加一个setSession方法,将session置入到你需要的对象中。
推荐用第二种。
分享到:
相关推荐
struts2 获取request session对象
struts2访问application、session以及request等web资源的示例代码
struts2中request和session的获取
Struts2中的session用法.docx
struts2_session_权限检查并控制重复登录 实在对不起各位,我当时有点冲忙上传上来个war包,现在我把源码奉上,真的对不起。我看了评论才知道,感谢那位仁兄。
STRUTS2获得session和request
用struts2实现session权限检查同时控制用户重复登录
Struts2的Action中获得request response session几种方法
简单的struts2拦截器利用session拦截用户登录.docx
JavaEE Struts2利用tokenSession防止重复提交
本文讲述了serlvet API无耦合的方式
这都是在学习,工作中总结出来的关于jsp,struts,EL,session,以及数据库方面的经验积累,希望对你有所帮助——
Struts2实现检查用户是否登录使用session操作存储用户信息
NULL 博文链接:https://aimilin6688.iteye.com/blog/1279546
记录了如何在struts2的action中使用session,方便以后直接引用
struts1.2增删改查分页Filter Session
从开发者角度看,就是说需要显示给用户的数据可以直接从Action中获取,而不像Struts1.x那样,必须把相应的Bean存到Page、Request或者Session中才能获取。Struts1.x 必须继承org.apache.struts.action.Action或者其...
1 判断session是否失效 本实例没测试这个问题 但在工作项目中碰到了 但原因在这里记录下:web应用会存在一个session 而uploadify上传时也会产生一个新的session 导致在后台判断session是否失效时获取的session为null...
视频第一部分共两部分 下载前请阅读博客文章详细 博文链接:https://dlivan.iteye.com/blog/68374
而不像Struts1.x那样,必须把相应的Bean存到Page、Request或者Session中才能获取。 Struts1.x 必须继承org.apache.struts.action.Action或者其子类,表单数据封装在FormBean中。 Struts 2无须继承任何类型或实现...