Struts2中 ValueStack、ActionContext、ServletContext、request、session等 表格解析

变量 从ActionContext中获得 生命周期 用Ongl来读取值 使用ServletConfigInterceptor来注入
ActionContext类 静态方法ActionContext. getContext() 一次Http请求 使用“#”加上key,如“#name” 无法注入
ValueStack类 ActionContext. getValueStack() 一次Http请求 直接填写来访问栈中对象的方法,或者使用top来直接获得栈中对象 无法注入
HttpServletRequest类 ActionContext. get( StrutsStatics. HTTP_REQUEST) 一次Http请求 无方便的方法 实现ServletRequestAware接口
request的Map ActionContext. get("request") 一次Http请求 使用“#request”再加上key,如“#request.name”或者“#request['name']” 实现RequestAware接口
parameters的Map ActionContext. get( "parameters") 一次Http请求 使用“# parameters”再加上key,如“#parameters .name”或者“#parameters ['name']” 实现ParameterAware接口
HttpServletSession类 无(需通过HttpServletRequest来获得) 一次Http Session会话 无方便的方法 无法注入
session的Map ActionContext. get("session") 每次请求创建,但在一次Http Session会话中数据都是一样的 使用“#session”再加上key,如“# session.name”或者“#session ['name']” 实现SessionAware接口
ServletContext类 ActionContext. get( StrutsStatics. SERVLET_CONTEXT) 网站项目启动后一直存在且唯一 无方便的方法 使用ServletContextAware接口
application的Map ActionContext.get( "application") 每次请求时创建,但其中的数据是网站项目启动后一直存在且共享 使用“# application”再加上key,如“#application .name”或者“#application ['name']” 使用ApplicationAware接口
原文地址:https://www.cnblogs.com/shaohz2014/p/3656637.html