If you are working on the Struts 2 applications, you would have noticed that while configuring the Struts 2 filter in your web.xml deployment descriptor, there is two different classes are used. One is org.apache.struts2.dispatcher.FilterDispatcher and another one is org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.
The simple answer is,
- org.apache.struts2.dispatcher.FilterDispatcher – Used in the early development of Struts 2 and deprecated from the version 2.1.3
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter – Introduced from the Struts 2.1.3. If you are using the higher version, it is always recommended to use this API.
FilterDispatcher Configuration
<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>
StrutsPrepareAndExecuteFilter Configuration
<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>