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

转载于:https://www.cnblogs.com/plxx/p/5337271.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值