struts ActionContext ThreadLocal
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的更多相关文章
- S2-045漏洞初步分析
0x01 前言 前几天刚分析完s2-032这个漏洞,今天又爆发了一个s2-045的漏洞,又是直接的命令执行,影响了struts2绝大多数的版本. 官方给的漏洞公告在这里 https://cwiki ...
- java必备基础知识点
Java基础 1. 简述Java的基本历史 java起源于SUN公司的一个GREEN的项目,其原先目的是:为家用消费电子产品发送一个信息的分布式代码系统,通过发送信息控制电视机.冰箱等 2. 简单写出 ...
- struts2 之 ThreadLocal 和 ActionContext
1. ThreadLocal:该类提供了线程局部(thtead-local)变量.threadLocal是一个容器,该容器中存放的数据可以保证线程安全. 案例如: public class Threa ...
- Struts中ActionContext和ServletActionContext的比较
一.ActionContext在Struts2开发中除了将请求参数自动设置到Action的字段中,往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直 ...
- java之struts2的ThreadLocal和ActionContext
在之前的学习中,我们知道struts2可以将表单中的数据自动设置到处理类的属性上,还有类型转换等其他功能.那么struts2是怎样做这件事情的呢? struts2完成这些功能是通过拦截器来完成的,并且 ...
- Struts 中 ActionContext ctx.put()把数据放到ValueStack里之数据传输背后机制:ValueStack(值栈)
1. 数据传输背后机制:ValueStack(值栈) 在这一切的背后,是因为有了ValueStack(值栈)! ValueStack基础:OGNL要了解ValueStack,必须先理解OGNL ...
- struts框架值栈问题三之值栈的创建和ActionContext对象的关系
3. 问题三 : 值栈对象的创建,ValueStack 和 ActionContext 是什么关系? * 值栈对象是请求时创建的 * ActionContext是绑定到当前的线程上(一个Action访 ...
- 转:ServletContext,ActionContext,ServletActionContext
ServletContext ServletContext从他的package信息可以看出,它是标准的JavaEE WebApplication类库 javax.servlet.ServletCont ...
- Struts2中ActionContext和ServletActionContext
转自:http://blog.sina.com.cn/s/blog_6c9bac050100y9iw.html 在Web应用程序开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在A ...
随机推荐
- Spring的lookup-method标签
Spring的解析源码 public void parseLookupOverrideSubElements(Element beanEle, MethodOverrides overrides) { ...
- nodeAPI--HTTP
HTTP: //超文本协议,是属于TCP上层的协议 http协议构建在请求和响应概念上,node.js中对应http.ServerRequest,http.ServerResponse; 当用户浏 ...
- 贪心 Codeforces Round #300 A Cutting Banner
题目传送门 /* 贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx, 接下来mx次循环,若是0,输出0:若是1,输出1,s[j]--: 注意:之前的0的要忽略 */ #inc ...
- BZOJ1444 : [Jsoi2009]有趣的游戏
建立AC自动机,并求出转移矩阵. 再用$\sum E(终止节点)=1$去替换第一个方程,高斯消元即可. 时间复杂度$O(n^3l^3)$. 注意精度问题,要特判0.00的情况. #include< ...
- FFMPEG解码流程
FFMPEG解码流程: 1. 注册所有容器格式和CODEC: av_register_all() 2. 打开文件: av_open_input_file() 3. 从文件中提取流信息: av_f ...
- MySQL配置SQL Assistant提示
以前开发一直使用SQL Server数据库,提示插件采用的就是SQL Assistant,写起脚本来相当有效率.这段时间公司转型要采用MySQL数据库,试用了mysql workbench.mysql ...
- FreeMarker教程
一.什么是模板引擎,为什么要用模板引擎 在B/S程式设计中,常常有美工和程序员二个角色,他们具有不同专业技能:美工专注于表现——创建页面.风格.布局.效果等等可视元素:而程序员则忙于创建程式的商业流程 ...
- Coremail邮件系统存储型XSS两个
(1):Coremail邮件系统存储型XSS之一 给受害者发送主题如下的邮件: <svg onload='img=new Image();img.src="//x55.me/geo.p ...
- Delphi 复习代码
1.取得可文件路径 Path := ExtractFilePath(Application.ExeName); //取得可执行文件路径 TXMLDocument.Create(ExtractFileP ...
- Eclipse中部署hadoop2.3.0
1 eclipse中hadoop环境部署概览 eclipse 中部署hadoop包括两大部分:hdfs环境部署和mapreduce任务执行环境部署.一般hdfs环境部署比较简单,部署后就 可以在ecl ...