Struts2-ActionContext
官方解释:
The ActionContext is the context in which an {@link Action} is executed. Each context is basically a container of objects an action needs for execution like the session, parameters, locale, etc. The ActionContext is thread local which means that values stored in the ActionContext are unique per thread. See the {@link ThreadLocal} class for more information. The benefit of this is you don't need to worry about a user specific action context, you just get it:
<code>ActionContext context = ActionContext.getContext();</code>
Finally, because of the thread local usage you don't need to worry about making your actions thread safe.
ActionContext是一个Action执行的上下文(现场).每一个Context是一个action执行所需要的数据的容器,这个容器中保存着session,parameters,locale等等.The ActionContext is thread local which means that values stored in the ActionContext are unique per thread. 这样设计的好处就是让开发者不用担心action的使用,只需要大胆使用就可以了,无需来保证它的线程安全.
原来我们所取得的ctx来自于 ThreadLocal 啊!熟悉ThreadLocal 的朋友都知道它是与当前线程绑定的
Struts2自定义的一个数据的容器.ActionContext是个map集合,它持有了web标准的4个域(pagecontext域,request域,session域,application域(servlet开发 context)),通过它可以直接获取这四个标准容器。
不仅如此,它还引用了其它struts 2自己定义的对象:
ActionContext的几个特点:
1,ActionContext是strtuts2新设计出来的存储数据的容器,该容器是个map集合,
它里面持有到达各个容器(其它map)的引用,如可以获取标准的4个域容器,还有struts 2自己定义的东西,如valuestack值栈
2,我们可以通过 ActionContext方便的获取到其它容器,如同一个快捷方式,是struts 2的数据中心。
3,ActionContext是threadloacl线程绑定的, 当struts 2接受到请求后,就会马上创建一个ActionContext,然后各个位置都可以获取到ActionContext
4,ActionContext意思就是action运行的上下文,负责存储action运行需要/产生的数据
5,ActionContext它里面有个map集合用来存储数据,但是ActionContext本身作为一个对象,它也有很多其它开发方法 。
ActionContext.getcontext() :获取ActionContext里的大map集合;ActionContext.getcontext().getvaluestack() //获取值栈
[参考]
http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E7%89%9B/32881.shtml
最新文章
- AngularJs2与AMD加载器(dojo requirejs)集成
- ASP.NET Core的Kestrel服务器
- Java并发编程:线程池的使用
- gradle项目中资源文件的相对路径打包处理技巧
- linux kernel链表
- SQL高级查询——50句查询(含答案) ---参考别人的,感觉很好就记录下来留着自己看。
- 替换所有的cell的右侧箭头
- C# 使用Trace记录程序日志
- scrollIntoView
- Activiti源码浅析:Activiti的活动授权机制
- 小蔡计算器 V4.0新版全新发布上线啦~欢迎大家下载使用哈~
- imageWithContentsOfFile读取全路径返回的image为空的解决方法
- Solr集群的搭建以及使用(内涵zookeeper集群的搭建指南)
- Lowest Common Ancestor of a Binary Tree——Leetcode
- Mac os 上可执行jar包转app方法
- 走向DBA[MSSQL篇] 详解游标
- 快速构建Windows 8风格应用5-ListView数据控件
- ionic项目结构解析
- java时间格式
- python 类和元类(metaclass)的理解和简单运用