`

Spring配置之ActionContextCleanUp

阅读更多
参考:
ActionContextCleanUp的作用:http://blog.csdn.net/oyxm0/article/details/7360214

涉及类:org.apache.struts2.dispatcher.ActionContextCleanUp

一、说明
在Struts 2.1.6之前,ActionContextCleanUp的完整路径是com.opensymphony.webwork.dispatcher.ActionContextCleanUp,现在的路径变成了org.apache.struts2.dispatcher.ActionContextCleanup。
延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让action自己清除。

     那么这个类究竟有什么用处呢?是不是一定要用呢?

     下面是这个类内部的注释。

     Special filter designed to work with the FilterDispatcher and allow
for easier integration with SiteMesh. Normally, ordering your filters to have
SiteMesh go first, and then FilterDispatcher go second is perfectly fine.
However, sometimes you may wish to access Struts features, including the value stack, from within your SiteMesh decorators. Because FilterDispatcher
cleans up the ActionContext, your decorator won't have access to the
data you want.
     By adding this filter, the FilterDispatcher will know to not clean up and instead defer cleanup to this filter. The ordering of the filters should then be:
1.this filter

2.SiteMesh filter

3.FilterDispatcher

    就是说,一般情况下,如果你要用SiteMesh或者其他过滤器,一般是放在FilterDispatcher或者是现在的StrutsPrepareAndExecuteFilter之前。在调用完所有过滤器的doFilter方法后,核心过滤器FilterDispatcher或者StrutsPrepareAndExecuteFilter会清空ActionContext,如果其他过滤器要一直使用value stack等struts的特性时,如果不用ActionContextCleanUp的话,便得不到想要的值。
    ActionContextCleanUp的作用就是上面用粗体标注出来的那一句。它会在doFilter方法里设置一个计数器counter的初始值为1,有了这个值,后续的核心过滤器就不会清空ActionContext,而是由之前的过滤器也就是ActionContextCleanUp来清空ActionContext。


什么是valuestack?http://hi.baidu.com/c%B3%E6c%B3%E6/blog/item/c8f63518e77fbe028718bf56.html

分享到:
评论

相关推荐

    spring2.5.4+hibernate3.2.6+struts2+jbpm3.2.2配置方法

    在`web.xml`中,`context-param`标签用于指定Spring配置文件的位置,如`applicationContext-resources.xml`、`applicationContext-dao.xml`和`/WEB-INF/applicationContext.xml`,这些文件定义了bean的配置和依赖...

    Struts+Spring+Ibatis整合框架搭建文档

    - **作用**:配置Spring的初始化参数,指定Spring配置文件的位置,启动时自动加载该文件。 2. **添加Struts2配置** - 使用上面提到的`FilterDispatcher`和`ActionContextCleanUp`配置。 3. **整合Ibatis配置** ...

    spring2.5.4+hibernate3.2.6+struts2+jbpm3.2.2收藏

    在配置中,`context-param`用于指定Spring配置文件的位置,例如`applicationContext-resources.xml`、`applicationContext-dao.xml`和`WEB-INF/applicationContext.xml`。`CharacterEncodingFilter`用于确保所有HTTP...

    struts2+spring+hibernate整合

    `applicationContext.xml`(或类似的Spring配置文件)用于定义Spring管理的Bean和事务管理策略;`hibernate.cfg.xml`用于配置Hibernate连接数据库的信息和映射文件位置。 2. **过滤器设置**:在`web.xml`中,除了...

    解决struts2.1.6+spring+hibernate 中文乱码

    - **struts.objectFactory = spring**:此配置项指定了Struts2使用Spring容器管理Action对象的生命周期。 - **struts.i18n.reload=true**:该配置项开启国际化资源文件的热加载功能,即当资源文件发生变化时,无需...

    spring+struts2+hibernate框架jar包

    通常,需要在web.xml中配置DispatcherServlet、Filter和ActionContextCleanUp,以及Spring的ApplicationContext配置文件路径。接着,编写Struts2的配置文件,定义Action及其对应的视图和业务方法。最后,配置...

    ssh maven框架

    `contextConfigLocation`参数指定了Spring配置文件的位置,这里设置为类路径下的`applicationContext-services.xml`。 Hibernate是SSH中的持久层框架,虽然在描述中没有直接提及,但通常SSH项目会用到Hibernate来...

    ssh框架整合步骤

    - 配置`ContextLoaderListener`:用于加载Spring的ApplicationContext.xml配置文件,确保Spring容器能够初始化。 - 配置`FilterDispatcher`:这是Struts2的过滤器,负责拦截所有的HTTP请求,将请求转发到相应的...

    SSH连接Oracle数据库.txt

    这段配置指定了Spring配置文件的位置,并启用了Spring的上下文加载监听器。此外,还配置了一个Struts过滤器,用于处理Struts框架相关的请求。 综上所述,通过以上配置,SSH框架可以成功连接并操作Oracle数据库。...

    S2SH三大框架面试题

    以上内容是针对Struts2的部分面试题解析,Spring和Hibernate框架的面试题通常会涉及依赖注入、事务管理、数据持久化等方面的知识,具体问题会涵盖各自的特性、配置、最佳实践等。对于Spring,可能需要了解IoC容器、...

    ssh框架学习指南介绍ssh的框架结构

    - `<context-param>`:设置Spring上下文配置文件的位置。 ```xml <param-name>contextConfigLocation /WEB-INF/daoContext.xml,/WEB-INF/applicationContext.xml ``` - `<listener>`:初始化Spring...

    SSH三大框架整合步骤

    此文件也位于`WEB-INF`目录下,用于配置Spring的Bean以及相关的事务管理器等。下面是一个简单的示例: ```xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...

    Struts2.1.8培训资料(推荐)

    配置正确的`StrutsPrepareAndExecuteFilter`后,不再需要单独配置`ActionContextCleanUp`过滤器,因为它在Struts2.1.3之后已被弃用。`ActionContextCleanUp`的作用是与`FilterDispatcher`协作,提供更灵活的SiteMesh...

    Struts2.docx

    在Struts2的工作流程中,客户端发起的请求首先会经过一系列过滤器,其中包括ActionContextCleanUp过滤器,它有助于Struts2与其他框架如SiteMesh的集成。接着,FilterDispatcher作为控制器的核心,根据ActionMapper的...

    struts2.1.6解决乱码 补充

    这些参数指定了Log4j配置文件以及Spring应用上下文的配置文件位置。 通过上述配置,我们可以有效地解决Struts2.1.6中的乱码问题。需要注意的是,在实际开发中可能还需要考虑其他因素,比如数据库连接、JSP页面编码...

    SSH的jar包.rar

    2、这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器,这个过滤器对于Struts2和其他框架的集成很有帮助,例如:SiteMesh Plugin) 3、接着FilterDispatcher被调用,...

    三大框架的原理

    - **IoC**:Spring通过XML或注解配置管理对象,包括创建实例、建立依赖关系。在`applicationContext.xml`中定义Bean,通过`class`属性指定类名,`property`和`constructor-args`设置属性和构造函数参数。Spring通过...

    struts2开发文档

    - **Hibernate & Spring**: 与ORM框架Hibernate和依赖注入框架Spring的整合,便于数据库操作和事务管理。 八、工作流程 1. 客户端发起HTTP请求到Servlet容器(如Tomcat)。 2. 请求经过一系列过滤器,可能包括...

    适合新手的ssh三大框架工作原理

    2. 请求经过一系列过滤器,包括ActionContextCleanUp,帮助与其他框架集成。 3. FilterDispatcher被调用,它会询问ActionMapper来决定是否需要调用特定的Action。 4. ActionProxy根据Configuration Manager找到...

Global site tag (gtag.js) - Google Analytics