Home  >  Struts 2

Struts 2 StrutsPrepareAndExecuteFilter in web.xml

By Arvind Rai, April 30, 2014
StrutsPrepareAndExecuteFilter belongs to org.apache.struts2.dispatcher.ng.filter package. StrutsPrepareAndExecuteFilter can also be understood by its name. StrutsPrepareAndExecuteFilter has the responsibility to prepare and execute all phases of struts. The question is when we should use StrutsPrepareAndExecuteFilter filter. Struts 2 apache documentation says that when there is no other filter being used that can access action context information, better to use StrutsPrepareAndExecuteFilter filter. Now we will see how to use this filter in web.xml
web.xml
<web-app>
  <display-name>Struts 2 Example</display-name>
   <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.concretepage.action</param-value>
        </init-param>
    </filter>
  <filter-mapping>
	<filter-name>struts2</filter-name>
	<url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app> 
In web.xml, we need to define filter and filter mapping. We can provide filter URL pattern on the basis of which URL will be served by StrutsPrepareAndExecuteFilter . In the constructer, init parameter can be passed. In the above filter definition, we are passing action package where all the action classes has been declared. On the basis of given action package, StrutsPrepareAndExecuteFilter filter scans all the action classes.

Download Source Code of Complete Example

POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us