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
Struts2-ActionContext的更多相关文章
- struts2中 ServletActionContext与ActionContext区别
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- Struts2中ActionContext及ServletActionContext介绍(转载)
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- ActionContext和ServletActionContext区别
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- Struts2中获取HttpServletRequest,HttpSession等的几种方式
转自:http://www.kaifajie.cn/struts/8944.html package com.log; import java.io.IOException; import java. ...
- ActionContext和ServletActionContext小结(转)
ActionContext和ServletActionContext小结 1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Act ...
- ActionContext和ServletActionContext小结
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- struts2中action手动获取參数
struts2中action手动获取Session,jsp页面參数 1. ActionContext 在Struts2开发中,除了将请求參数自己主动设置到Action的字段中,我们往往也须要在Acti ...
- ActionContext 与 ServletActionContext获取Session的异同
1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息, ...
- 获得HttpServletResponse及其他对象
下面只列出获得 HttpServletResponse 对象的方法,获得 HttpServletRequest 对象方法类似. 在struts1.x Action类的execute方法中,有四个参数, ...
- 在Action类中获得HttpServletResponse对象的四种方法
在struts1.xAction类的execute方法中,有四个参数,其中两个就是response和request.而在Struts2中,并没有任何参数,因此,就不能简单地从execute方法获得Ht ...
随机推荐
- Dokcer 组成原理简介
首先来张图了解Docker的组成 重要 Docker在启动容器的时候,需要创建文件系统,为rootfs提供挂载点.最初Docker仅能在支持Aufs文件系统的Linux发行版上运行,但是由于Aufs未 ...
- synchronized和vilatile
第一个程序 public class Test06 implements Runnable{ public int a = 0; public static void main(String[] ar ...
- Storm几篇文章
http://tianhailong.com/ http://www.cnblogs.com/panfeng412/archive/2012/07/02/storm-common-patterns-o ...
- nginx启动、开机自启动、重启、关闭
yum -y install nginx # yum info nginx Loaded plugins: fastestmirror Loading mirror speeds from cach ...
- Sicily-1438
一. 题意 买二送一.排序之后隔三求和,求折扣的最大值. 二. 代码 // // main.cpp // sicily-1438 // // Created by ashley o ...
- java线程学习——汉堡销售问题
汉堡店中有一个负责做汉堡的厨师,一个负责销售的营业员,用java线程表示他们的营业过程: 问题原型就是生产者与消费者的问题. 首先定义一个汉堡包箱子类与几个相关的变量类: public class H ...
- JavaScript 数字相关的转换和方法
类型判断 isNaN - 是否是 NaN(Not a Number).主要用来判断 NaN 是否是 NaN,因为 NaN == NaN 是 false. isNaN(NaN); // tr ...
- Decorator Pattern(装饰模式)
装饰模式:动态的给一个对象添加一些额外的职责.当然我们也可以通过继承来实现类似的功能,但是随着子类的增多,各种子类的组合会造成子类的急剧膨胀. Requirement: 假设客户有一个要求,需要打一个 ...
- sql 和 nosql 说明
在传统的数据库中, 数据库的格式是由表(table).行(row).字段(field)组成的.表有固定的结构,规定了每行有哪些字段,在创建时被定义,之后修改很困难.行的格式是相同的,由若干个固定的字段 ...
- Task线程 同时执行多个任务
Task taskTest = Task.Factory.StartNew(() => { Console.WriteLine("); },TaskCreationOptions.No ...