Difference Between FilterDispatcher and StrutsPrepareAndExecuteFilter in Struts 2

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>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!