Struts2-ActionContext
2016-03-30 15:08
645 查看
官方解释:
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
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
相关文章推荐
- Java基础05 实施接口
- java 向手机发送消息
- android eclipse 导入idea项目
- java.util.concurrent.locks与synchronized
- Java语言基础系列之2--用IDEA中文编码问题
- Java定时器quartz和spring集成
- Android Studio 补全提示,类似Eclipse快捷键"Alt+/"的用法
- Eclipse的Graphical Layout页面下没有界面视图,报错Failed to find the style corresponding to the id 2130772027
- java.lang.IllegalStateException: closed when trying to access response in onResponse(Response respon
- Netty 服务器客户端,发送自定义消息
- spring,IOC和AOP的解析原理和举例
- SpringMVC+Spring3+hibernate4 开发环境搭建以及一个开发实例教程
- JavaWeb学习总结(十七)——JSP中的九个内置对象
- Spring的IOC,AOP产生的原因
- JAVA 页面隐藏手机号或者身份证号
- ubuntu配置JDK
- JavaWeb那些事儿(一)--为什么做java的web开发使用struts2,springMVC和spring这样的框架
- [Java]循环步长不要设置成小数
- Java调优之jvm和线程的内存分析
- Struts2基础学习总结