当前位置: 首页 > news >正文

ActionContext 中的数据详解

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

部分参考《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)

  

转载于:https://my.oschina.net/braveCS/blog/548802

相关文章:

  • SpringMVC格式总结
  • QT内使用OpenCV
  • FRC与tableview的联合使用
  • Sublime Text 3安装与使用
  • 解放全天下开发者
  • Cesium 获取当前视图范围
  • Gradle介绍
  • 扩展SpringMVC以支持绑定JSON格式的请求参数
  • 0x05 Python数据分析,Anaconda八斩刀
  • dos保存adb logcat读取的Android信息
  • Rotate Image LeetCode
  • MFC消息映射与命令传递
  • CentOS6.6下解压安装mysql-5.7.10-linux-glibc2.5-i686.tar.gz
  • myeclipse安装插件phpeclipse后进行PHP代码编写
  • 怎样选择前端框架
  • 深入了解以太坊
  • [译]如何构建服务器端web组件,为何要构建?
  • 【译】React性能工程(下) -- 深入研究React性能调试
  • angular学习第一篇-----环境搭建
  • bearychat的java client
  • create-react-app做的留言板
  • crontab执行失败的多种原因
  • Java 实战开发之spring、logback配置及chrome开发神器(六)
  • socket.io+express实现聊天室的思考(三)
  • spring security oauth2 password授权模式
  • Vue2.0 实现互斥
  • 和 || 运算
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 猫头鹰的深夜翻译:Java 2D Graphics, 简单的仿射变换
  • 你真的知道 == 和 equals 的区别吗?
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • media数据库操作,可以进行增删改查,实现回收站,隐私照片功能 SharedPreferences存储地址:
  • 选择阿里云数据库HBase版十大理由
  • ​​​​​​​GitLab 之 GitLab-Runner 安装,配置与问题汇总
  • ​iOS安全加固方法及实现
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • (2022版)一套教程搞定k8s安装到实战 | RBAC
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (安卓)跳转应用市场APP详情页的方式
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (十二)python网络爬虫(理论+实战)——实战:使用BeautfulSoup解析baidu热搜新闻数据
  • (五)网络优化与超参数选择--九五小庞
  • (原)本想说脏话,奈何已放下
  • (转)3D模板阴影原理
  • (转)重识new
  • .apk文件,IIS不支持下载解决
  • .bat批处理(二):%0 %1——给批处理脚本传递参数
  • .Net Framework 4.x 程序到底运行在哪个 CLR 版本之上
  • .net对接阿里云CSB服务
  • .net专家(高海东的专栏)
  • ??javascript里的变量问题
  • @data注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • @NoArgsConstructor和@AllArgsConstructor,@Builder
  • [100天算法】-目标和(day 79)
  • [20161101]rman备份与数据文件变化7.txt