zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Promises-小程序购物车结算
    微信小程序支付
    微信企业付款到零钱
    Ubuntu16 远程连接MySQL
    MySQL数据库中文变问号
    Ubuntu开启ApacheRewrite功能
    大数据2018:云存储已在客观层面扮演数据湖角色
    地平线发布兼具本地端抓拍与识别功能的嵌入式AI摄像机
    肥皂遇上黑科技!异味统统都走开!
    LG新专利或用于移动VR,可通过外部旋钮调节显示屏与透镜
  • 原文地址:https://www.cnblogs.com/plxx/p/5337271.html
Copyright © 2011-2022 走看看