部分参考《Struts2技术内幕》
ActionContext 作为ValueStack的上下文环境 <|——ServletActionContext
|——context:OgnlContext implements Map ActionContext.getContextMap(),ognl上下文
|——_root:CompountRoot extends ArrayList :ognl的根
| 内容:( HashMap:ActionContext.getValueStack().set(key,vlaue)用到的HashMap
| 当前Action实例
| DefaultTextProvider:)
|——classResolver:CompoundRootAccessor指定处理class loading的处理类
|——converter:OgnlTypeConverterWrapper指定处理类型转换的处理类
|——memberAccess:SecurityMemberAccess指定处理属性访问策略的处理方式
|——_value:HashMap :使用一个Map来维护ognl的上下文
===========ActionContext.context._value中的数据========================
Web原生对象:
Com.opensymphony.xwork2.dispatcher.HttpServletRequest——StrutsRequestWrapper
Com.opensymphony.xwork2.dispatcher.HttpServletResponse——ResponseFacade implements HttpServletResponse
Com.opensymphony.xwork2.dispatcher.ServletContext——ApplicationContextFacade
XWork封装对象:
Com.opensymphony.xwork2.ActionContext.application——ApplicationMap<K,V>
<——ActionContext.getApplication()
Com.opensymphony.xwork2.ActionContext.session——SessionMap<K,V>
<——ActionContext.getSession()
Com.opensymphony.xwork2.ActionContext.parameters——TreeMap<K,V> <——ActionContext.getParameters() 返回 HttpServletRequest(get|post,String[],有重复参数名也不覆盖)参数的map
Com.opensymphony.xwork2.util.ValueStack.ValueStack——OgnlValueStack <——ActionContext.getValueStack()
application——ApplicationMap<K,V>
session——SessionMap<K,V>
parameters——HashMap:
request——RequestMap
attri——AttributeMap
action——当前Action类
自定义key——自定义值:使用ActionContext.put(key,value),ActionContext.get(key)
Com.opensymphony.xwork2.ActionContext.name——fmCS:Action标签的name属性
<—— ActionContext.getName()
Com.opensymphony.xwork2.ActionContext.container——ContainerImpl:struts2的容器
<—— ActionContext.getContainer()
Com.opensymphony.xwork2.ActionContext.actionInvocation——DefaultActionInvocation
<——ActionContext.getActionInvocation()
Com.opensymphony.xwork2.ActionContext.conversionErrors——HashMap
<——ActionContext.getConversionErrors()
Com.opensymphony.xwork2.ActionContext.local——Lcale <——ActionContext.getLocale()
Struts2.actionMapping——ActionMapping
Xwork.NullHandler.createNullObjects——boolean
Xwork.MethodAccessor.denyMethodExecution——Boolean
Report.conversion.errors——Boolean
Current.property.path——
Last.property.accessed——
Last.bean.accessed——
======================================================================
OgnlValueStack:对ognl中的root对象的扩展,具有栈结构
|——context:OgnlContext,差不多就是ActionContext
|——root:CompoundRoot:对valuestack的操作用到的是这里的数据
ValueStack中的[n]表示除栈结构中前N个元素之后构成的元素集合。通过CompoundRoot的cutStack()实现。
使用装饰者模式
StrutsRequestWrapper——|>HttpServletRequestWrapper——|>ServletRequestWrapper
|——request:RequestFacade
|——request:Request
|——attributes:HashMap<K,V>
StrutsRequestWrapper有子类HttpServletRequestWrapper,实现HttpServletRequest接口
使用适配器模式
ApplicationMap
|——context:ApplicationContextFacade
|——entries:HashSet<Set>
public class ApplicationMap extends AbstractMap implements Serializable
Struts2 API解释:A simple implementation of the Map interface to handle a collection of attributes and init parameters in a ServletContext object. The entrySet() method enumerates over all servlet context attributes and init parameters and returns a collection of both. Note, this will occur lazily - only when the entry set is asked for
SessionMap
|——entries
|——request:StrtusRequestWrapper
|——session:StandardSessionFacade
public class SessionMap extends AbstractMap implements Serializable
Struts2 API解释:A simple implementation of the Map interface to handle a collection of HTTP session attributes. The entrySet() method enumerates over all session attributes and creates a Set of entries. Note, this will occur lazily - only when the entry set is asked for.
RequestMap
|——entries
|——request:StrutsRequestWrapper
public class RequestMap extends AbstractMap implements Serializable
Struts2 API解释:A simple implementation of the Map interface to handle a collection of request attributes.
AttributeMap
public class AttributeMap implements Map
Struts2 API解释:
A Map that holds 4 levels of scope.
The scopes are the ones known in the web world.:
Page scope
Request scope
Session scope
Application scope
A object is searched in the order above, starting from page and ending at application scope.
===================================================================
Struts2下的FreeMarker:
参考Struts2API类FreemarkerResult的createModel方法:
Build the instance of the ScopesHashModel, including JspTagLib support
Objects added to the model are
//1)Application - servlet context attributes hash model atc.getApplication().put("fmApplication", "application 测试"); ${Application.fmApplication} //2)Request - request attributes hash model ServletActionContext.getRequest().setAttribute("servletRequestFM", "原生Request 测试"); ${Request.servletRequestFM} //3)Session - session attributes hash model atc.getSession().put("fmSession", "session 测试"); ${Session.fmSession} //4)stack - the OgnLValueStack instance for direct access atc.put("fmActionContext", "actionContext 测试"); ${stack.context.fmActionContext} atc.getValueStack().set("fm_set_ValueStack", "valueStack set 测试"); ${stack.root[0].fm_set_ValueStack} //5)action - the action itself private String fmStr="action 域 FreeMarker 测试"; getter,setter ${action.fmStr} //6)request - the HttpServletRequst object for direct access //7)response - the HttpServletResponse object for direct access //8)ognl - the instance of the OgnlTool //9)JspTaglibs - jsp tag lib factory model //10)struts - instance of the StrutsUtil class //11)exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages)