Struts2中的FilterDispatcher和StrutsPrepareAndExecuteFilter的區別
阿新 • • 發佈:2018-12-26
轉自:http://blog.csdn.net/lifuxiangcaohui/article/details/8172956在Struts2開發中,很多人問到,宣告過濾器的時候,為什麼有的時候用"FilterDispatcher",而有的時候用"StrutsPrepareAndExecuteFilter"?兩者都可以正常工作,那區別是什麼呢?
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern >
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name >struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>答案FilterDispathcer (
1. FilterDispatcher 例子
...<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern
</filter-mapping>
2. StrutsPrepareAndExecuteFilter 例子
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name
<url-pattern>/*</url-pattern>
</filter-mapping>答案FilterDispathcer (
org.apache.struts2.dispatcher.FilterDispatcher
) 在早期的Struts2開發中使用,從Struts 2.1.3開始,它已不推薦使用。如果你使用的Struts的版本 >= 2.1.3,推薦升級到新的Filter-StrutsPrepareAndExecuteFilter (org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)。