Struts 2 MVC Pattern

M-Model- It manages the data for application and encapsulates the business logic for request processing. It is as simple as a java bean with execute method. Or we can implement the same by extending ActionSupport class.

V-View- It is the presentation layer. It can be JSP, Velocity, Freemarker etc.

C-Controller- It inspects each incoming request to determine the action to do processing and send back the result. It is specified in web.xml

1. FilterDispatcher example

  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
       org.apache.struts2.dispatcher.FilterDispatcher
      </filter-class>
      <init-param>
         <param-name>struts.devMode</param-name>
         <param-value>true</param-valu>>
      </init-param>
   </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>
      <init-param>
         <param-name>struts.devMode</param-name>
         <param-value>true</param-valu>>
      </init-param>
   </filter>

   <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

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

It is always recommended to use new class - StrutsPrepareAndExecuteFilter (org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)