web.xml配置解析(8)

发布时间:2021-06-06

<filter-mapping>

<filter-name>struts2CleanupFilter</filter-name>

<url-pattern>*.action</url-pattern>

<dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher>

</filter-mapping>

配置解释:一般情况下,如果你要用SiteMesh或者其他过滤器,一般是放在

FilterDispatcher或者是现在的StrutsPrepareAndExecuteFilter之前。在调用完所有过滤器的doFilter方法后,核心过滤器FilterDispatcher或者

StrutsPrepareAndExecuteFilter会清空ActionContext,如果其他过滤器要一直使用value stack等struts的特性时,如果不用ActionContextCleanUp的话,便得不到想要的值。

ActionContextCleanUp的作用就是在doFilter方法里设置一个计数器counter的初始值为1,有了这个值,后续的核心过滤器就不会清空ActionContext,而是由之前的过滤器也就是ActionContextCleanUp来清空ActionContext。

3. StrutsPrepareAndExecuteFilter

配置信息:

<filter>

<filter-name>struts2Filter</filter-name>

<filter-class>

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class>

</filter>

<filter-mapping>

<filter-name>struts2Filter</filter-name>

<url-pattern>*.action</url-pattern>

<dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher>

</filter-mapping>

配置解释:

Struts2的核心过滤器,必须配置。

精彩图片

热门精选

大家正在看