ActionContextCleanUp

一般情况下,如果要用sitemesh或者其他过滤器时,是要放在filterDispatcher前面的,在调用完所有的dofilter()后,filterDispatcher会清空actionContext,其他过滤器如果要使用valueStack等等struts的特性时, 就得不到想要的值.

ActionContextCleanUp延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让action自己清除。

    为了使用WebWork,我们只需要在web.xml配置FilterDispatcher一个过滤器即可,阅读一下FilterDispatcher的JavaDoc和源码,我们可以看到它调用了:

 finally
 {
            ActionContextCleanUp.cleanUp(req);
 } 

在ActionContextCleanUp中,有这样的代码:

req.setAttribute(CLEANUP_PRESENT, Boolean.TRUE); 

如果FilterDispatcher检测到这个属性,就不会清除ActionContext中的内容了,而由ActionContextCleanUp后续的代码来清除,保证了一系列的Filter访问正确的ActionContext.

ActionContextCleanUp过滤器的位置一般在前面:

 ActionContextCleanUp filter
 SiteMesh filter
 FilterDispatcher

原文地址:https://www.cnblogs.com/wangjianbg/p/3443444.html