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 ...
随机推荐
- 2016.6.11 ASP提交数据到SQL server数据乱码解决方法
1.检查数据库排序规则 China-PRE-90-CS-AI 2.ASP文档中,写入数据的页面的编码和检查提交数据页面的编码一致:
- javascript优化--06模式(对象)01
命名空间: 优点:可以解决命名混乱和第三方冲突: 缺点:长嵌套导致更长的查询时间:更多的字符: 通用命名空间函数: var MYAPP = MYAPP || {}; MYAPP.namespace = ...
- Codeforces Round #330 (Div. 2)
C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了. 水 A - Vitaly and Night /***************************************** ...
- BZOJ4032 : [HEOI2015]最短不公共子串
第一问: 对B串建立SAM,暴力枚举A的每个子串,在SAM上走,若失配则可行. 第二问: 设g[i][j]表示B串的第i个字符之后最早出现的字符j的位置,暴力枚举A的每个子串,按照g贪心地走,若失配则 ...
- c++ string 结束符‘\000’
昨天输出string类型时总是出错,发现输出到文件的一行里多了^@,输出到console却看不到,debug发现,string类型中多了\000,这主要由于我想要用\0截掉字符串最后一位,所以把字符串 ...
- MySQL删除更新数据时报1175错误的问题
今天删除mysql数据库中的一条记录的时候,一直不能删除,提示错误信息如下: Error Code: 1175. You are using safe update mode and you trie ...
- Quest Central for DataBase 5.0.1,6.1 (软件+注册)
找寻了多天,终于找到了,记录下,以后重装用.输入所有组件的licenses后,提示要注册,我选择了Canada,Google了一个地方的PostCode和phone number,填写,注册成功! 软 ...
- 关于inf的问题
详见实例 #include<algorithm> #include<iostream> #include<cstring> #include<cstdio&g ...
- Metronic_下拉列表Select2插件的使用
这个插件是基于Select的扩展插件,能够提供更加丰富的功能和用户体验,它的github官网地址为:https://select2.github.io/,具体的使用案例,可以参考地址:https:// ...
- SVN的学习和安装
SVN分为服务器版本和客户端版本 服务器:VISUALSVN SERVER https://www.visualsvn.com/server/download/ 安装和配置(都很简单,只要不断的下一步 ...