public class ActionContext implements Serializable

The ActionContext is the context in which an 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. The benefit

of this is you don't need to worry about a user specific action context, you just get it:

ActionContext context = ActionContext.getContext();

Finally, because of the thread local usage you don't need to worry about making your actions thread safe.

1.源码分析

 public class ActionContext implements Serializable {
static ThreadLocal actionContext = new ThreadLocal(); Map<String, Object> context; public ActionContext(Map<String, Object> context) {
this.context = context;
} public static ActionContext getContext() {
return (ActionContext) actionContext.get(); // Don't do lazy context creation, as it requires container; the creation of which may
// precede the context creation
//if (context == null) {
// ValueStack vs = ValueStackFactory.getFactory().createValueStack();
// context = new ActionContext(vs.getContext());
// setContext(context);
//} } public void setContextMap(Map<String, Object> contextMap) {
getContext().context = contextMap;
} //..... }

struts ActionContext ThreadLocal的更多相关文章

  1. S2-045漏洞初步分析

    0x01 前言 前几天刚分析完s2-032这个漏洞,今天又爆发了一个s2-045的漏洞,又是直接的命令执行,影响了struts2绝大多数的版本. 官方给的漏洞公告在这里   https://cwiki ...

  2. java必备基础知识点

    Java基础 1. 简述Java的基本历史 java起源于SUN公司的一个GREEN的项目,其原先目的是:为家用消费电子产品发送一个信息的分布式代码系统,通过发送信息控制电视机.冰箱等 2. 简单写出 ...

  3. struts2 之 ThreadLocal 和 ActionContext

    1. ThreadLocal:该类提供了线程局部(thtead-local)变量.threadLocal是一个容器,该容器中存放的数据可以保证线程安全. 案例如: public class Threa ...

  4. Struts中ActionContext和ServletActionContext的比较

    一.ActionContext在Struts2开发中除了将请求参数自动设置到Action的字段中,往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直 ...

  5. java之struts2的ThreadLocal和ActionContext

    在之前的学习中,我们知道struts2可以将表单中的数据自动设置到处理类的属性上,还有类型转换等其他功能.那么struts2是怎样做这件事情的呢? struts2完成这些功能是通过拦截器来完成的,并且 ...

  6. Struts 中 ActionContext ctx.put()把数据放到ValueStack里之数据传输背后机制:ValueStack(值栈)

    1.     数据传输背后机制:ValueStack(值栈) 在这一切的背后,是因为有了ValueStack(值栈)! ValueStack基础:OGNL要了解ValueStack,必须先理解OGNL ...

  7. struts框架值栈问题三之值栈的创建和ActionContext对象的关系

    3. 问题三 : 值栈对象的创建,ValueStack 和 ActionContext 是什么关系? * 值栈对象是请求时创建的 * ActionContext是绑定到当前的线程上(一个Action访 ...

  8. 转:ServletContext,ActionContext,ServletActionContext

    ServletContext ServletContext从他的package信息可以看出,它是标准的JavaEE WebApplication类库 javax.servlet.ServletCont ...

  9. Struts2中ActionContext和ServletActionContext

    转自:http://blog.sina.com.cn/s/blog_6c9bac050100y9iw.html 在Web应用程序开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在A ...

随机推荐

  1. SU suspike命令学习

    用默认参数生成的数据如下: 用别的软件打开数据查看, 依次查看4个脉冲的位置(第几道.出现的时间), 接下来我们做一些小练习,比如说在同一道上放两个脉冲 还可以增加道数,让脉冲位于不同地方,

  2. Xamarin Visual Studio提示找不到AssemblyAttributes.cs文件

    Xamarin Visual  Studio提示找不到AssemblyAttributes.cs文件   错误信息:Could not find file ‘C:\Users\[用户名]\AppDat ...

  3. SGU185 Two shortest(最小费用最大流/最大流)

    题目求一张图两条边不重复的最短路. 一开始我用费用流做. 源点到1连容量2费用0的边:所有边,连u到v和v到u容量1费用cost的边. 总共最多会增广两次,比较两次求得的费用,然后输出路径. 然而死M ...

  4. Viola Jones Face Detector

    Viola Jones Face Detector是Paul viola 和 Michael J Jones共同提出的一种人脸检测框架.它极大的提高了人脸检测的速度和准确率. 速度提升方面:利用积分图 ...

  5. Windows Phone7 快递查询

        (1)API去友商100里申请 布局代码: Exp.xaml <phone:PhoneApplicationPage x:Class="WindowsPhone_Express ...

  6. Nginx location 匹配规则

    1. default_server: 当请求没有匹配到服务器中配置的任何一个server的时候,会默认把请求route到配置了default_server的virtual host中.参考地址:htt ...

  7. shell中(),[]和[[]]的区别

    1. 首先,尽管很相似,但是从概念上讲,二者是不同层次的东西."[[",是关键字,许多shell(如ash bsh)并不支持这种方式.ksh, bash(据说从2.02起引入对[[ ...

  8. 给NSString增加Java风格的方法

    给NSString增加Java风格的方法 文章目录 我实在受不了 NSString 冗长的方法调用了,每次写之前都要查文档.特别是那个去掉前后多余的空格的方法,长得离谱.与之对应的别的语言,拿 jav ...

  9. rbegin 和 end 区别

    在使用C++的STL时,经常会用到迭代器,那么不得不搞清楚里面的一些指针 begin(), end(), rbegin(), rend()之间的区别与联系,以及它们分别都指向哪个元素.首先要明白的一点 ...

  10. The Stable Marriage Problem

    经典稳定婚姻问题 “稳定婚姻问题(The Stable Marriage Problem)”大致说的就是100个GG和100个MM按照自己的喜欢程度给所有异性打分排序.每个帅哥都凭自己好恶给每个MM打 ...