struts2的ActionContext类分析(action执行时所需对象的环境)
来源:互联网 发布:什么是优化发展环境 编辑:程序博客网 时间:2024/04/25 07:05
ActionContext是Action执行的一个环境。每一个ActionContext对象基本上是一个action执行所需
对象的容器,如session、parameters、locale等。(来自ActionContext API)
ActionContext是thread local的,这意味着保存在ActionContext中的值在每个线程中都是独有的。
这样就不用担心用户具体的action context,而且自己编写的actions也是线程安全的。
public class ActionContext implements Serializable { static ThreadLocal actionContext = new ThreadLocal(); /** * Constant for the name of the action being executed. */ public static final String ACTION_NAME = "com.opensymphony.xwork2.ActionContext.name"; public static final String VALUE_STACK = ValueStack.VALUE_STACK; public static final String SESSION = "com.opensymphony.xwork2.ActionContext.session"; public static final String APPLICATION = "com.opensymphony.xwork2.ActionContext.application"; public static final String PARAMETERS = "com.opensymphony.xwork2.ActionContext.parameters"; public static final String LOCALE = "com.opensymphony.xwork2.ActionContext.locale"; public static final String TYPE_CONVERTER = "com.opensymphony.xwork2.ActionContext.typeConverter"; public static final String ACTION_INVOCATION = "com.opensymphony.xwork2.ActionContext.actionInvocation"; public static final String CONVERSION_ERRORS = "com.opensymphony.xwork2.ActionContext.conversionErrors"; public static final String CONTAINER = "com.opensymphony.xwork2.ActionContext.container"; //用于存放对应Action执行时需要的对象,可以看出使用了Map来存放,上面的常量都是Map中key Map<String, Object> context; /** * Sets the action invocation (the execution state). */ public void setActionInvocation(ActionInvocation actionInvocation) { put(ACTION_INVOCATION, actionInvocation); } /** * Stores a value in the current ActionContext. The value can be looked up using the key. */ public void put(String key, Object value) { context.put(key, value); } /** * Gets the action invocation (the execution state). */ public ActionInvocation getActionInvocation() { return (ActionInvocation) get(ACTION_INVOCATION); } /** * Returns a value that is stored in the current ActionContext by doing a lookup using the value's key. */ public Object get(String key) { return context.get(key); } /** * Sets the action context for the current thread. */ public static void setContext(ActionContext context) { actionContext.set(context); }}
上面的代码不是完整的,仅仅保留了ActionContext类中的成员变量定义和几个方法。成员
变量中最重要的是Map<String, Object>类型 context。从下面的get方法可以看出,context成员
变量以键值对的方式存放Action执行时所需要的对象。其他的常量成员变量表示的是Map对象
context中的键值。像action执行所需的session,application,locale,valueStack,converter等
都可以从这个类中找到。
对应的ActionContext对象放置了一个ThreadLocal对象中,保证action执行环境是thread local
的,是线程安全的。
0 0
- struts2的ActionContext类分析(action执行时所需对象的环境)
- 从struts2的action中看ActionContext的存储结构
- Struts2---Action,action,ActionContext
- [例15.3] 为 Action 对象配置输出执行时间的拦截器, 查看执行 Action 所需时间
- Struts2的 ActionContext && ServletActionContext
- struts2的ActionContext
- Struts2的 ActionContext && ServletActionContext
- Struts2的 ActionContext && ServletActionContext
- Struts2的ActionContext
- struts2的ActionContext
- ActionContext对象的使用
- struts2的ActionContext到底是一个什么对象?
- 对struts2中ActionContext模拟及ThreadLocal的使用分析
- struts2的ActionContext源代码解析
- struts2 中的ActionContext的介绍
- Struts2的 ActionContext && ServletActionContext 区别
- struts2的ActionContext源代码解析
- struts2的action执行过程模拟
- 1.jstl
- 模拟javascript函数:
- Linux 配置支持高并发TCP连接(socket最大连接数)
- Spring 流程简述
- 一些基础知识
- struts2的ActionContext类分析(action执行时所需对象的环境)
- ubuntu12.04下设置类似QQ的截图功能
- 对Java类加载器的认识
- 模板路径常量传址到js文件中的小技巧
- RedHat Enterprise 5 LAMP服务器架设步骤
- javascript弹出对话框的几种形式
- C++之this指针与另一种“多态”
- 详解Linux2.6内核中基于platform机制的驱动模型
- 用户自定义文件的元数据