部分参考《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)
分享到:
相关推荐
主要介绍了Struts2 ActionContext 中的数据详解,需要的朋友可以参考下
JavaEE ActionContext存取数据示例
在Web应用程序开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话 (Session)的一些信息, 甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应...
NULL 博文链接:https://lijiejava.iteye.com/blog/628636
使用Action访问ActionContext方式的网站计数器,可直接运行
ActionContext(com.opensymphony.xwork.ActionContext)是Action执行时的上下文,上下文可以看作是一个容器(其实我们这里的容器就是一个Map而已),它存放放的是Action在执行时需要用到的对象
NULL 博文链接:https://zhouhaitao.iteye.com/blog/1126042
struts2大量使用拦截器来处理请求,从而允许与业务逻辑控制器 与 servlet-api分离,避免了侵入性(所谓侵入性就是指的这个架构设计出来的部件对系统的影响范围,标签库几乎可以完全替代JSTL的标签库,并且 struts2.x...
struts2OGNL表达式ActionContext及valuesStack.pdf
本案例提供ognl使用详解,测试通过,只需解压放入自己WEB项目中,执行struts_ognl包内java文件即可(未提供jia包,若需要可以联系留言发至邮箱),若测试不好可以联系本人提供指导. Struts 2默认的表达式语言是OGNL...
struts2 OGNL,struts2 表达式语言,Struts2 中OGNL表达式的用法,Struts2 #,表达式语言的好处,Struts2 $,struts2 井号,星号,百分号
struts2.0 详细介绍了struts.xml的配置,以及web.xml的配置和ActionContext,ServletActionContext的用法和区别。ActionContext主要用于设置属性,而ServletActionContext主要用来得到属性
SiteMesh简介: SiteMesh是一个Web页面布局... WebWork把全部值栈数据都保存在请求attribute中, 这意味着如果想显示值栈(或ActionContext)中的数据, 只需使用WebWork附带的标准标签库, 就这么简单!那来看完本文吧。
Sitemesh简介: SiteMesh是一个Web页面布局... WebWork把全部值栈数据都保存在请求attribute中, 这意味着如果想显示值栈(或ActionContext)中的数据, 只需使用WebWork附带的标准标签库, 就这么简单!那来看完本文吧。
SiteMesh是一个Web页面布局修饰... WebWork把全部值栈数据都保存在请求attribute中, 这意味着如果想显示值栈(或ActionContext)中的数据, 只需使用WebWork附带的标准标签库, 就这么简单!内含学习文档和完整例子。
在Struts2中底层的session都被封装成了Map类型,我们称之为SessionMap,而平常我们所说的session则是指HttpSession对象,具体的获得方法如下所示。 A.Map session=ActionContext.getSession(); B.Map session=(Map...
1、什么是值栈 2、值栈的内部结构 3、ActionContext和ValueStatck的关系 4、如何获取值栈对象 5、向值栈存数据 6、从值栈中获取数据
2、使用struts2提供的ActionContext类直接获取Servlet API。 在同一个项目中,如果既用到servlet又用了struts框架,运行项目时可能无法正常使用servlet,解决办法如下: 该类是定义了一个过滤器,当既用到struts2...