Question

In Struts2 development, many asked why some declared filter class as “FilterDispatcher“; others declared “StrutsPrepareAndExecuteFilter“? But both are working perfectly and what’s the different?

1. FilterDispatcher example

...
<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 example

...
<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>
...

Answer

The FilterDispatcher (org.apache.struts2.dispatcher.FilterDispatcher) is used in the early Struts2 development, and it’s deprecated since Struts 2.1.3.

If you are using Struts version >= 2.1.3, it’s always recommended to upgrade the new filter class – StrutsPrepareAndExecuteFilter (org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter).

References

  1. FilterDispatcher documentation
  2. StrutsPrepareAndExecuteFilter documentation
Note : You can find more similar articles at - Struts 2.x Tutorials