Struts2 Framework


There are many different web frameworks available for todays developer. Some of these come from Open Source communities, some from commercial companies, and yet others are internally developed for the current web development needs.

Some of the features that may lead us to consider Struts2:

  • Action based framework
  • Mature with a vibrant developer and user community
  • Annotation and XML configuration options
  • POJO-based actions that are easy to test
  • Spring, SiteMesh and Tiles integration
  • OGNL expression language integration
  • Themes based tag libraries and Ajax tags
  • Multiple view options (JSP, Freemarker, Velocity and


  • Plug-ins to extend and modify framework features


Struts2 is an action based MVC web framework. The Model- View-Controller pattern in Struts2 is realized with five core components actions, interceptors, value stack / OGNL, result types and results / view technologies.

Following figure shows the  MVC / Struts2 Architecture

strtus tutorial



The controller is implemented with a Struts2 dispatch servlet filter(FilterDispatcher) as well as interceptors, the model is implemented with actions, and the view as a combination of result types and results.  In Struts 2 the view is commonly implemented using JSP, Velocity Template, Freemaker or some other presentation-layer technology. The value stack and OGNL provide common thread, linking and enabling integration between the other components.


Work flow of Struts2 application

  Initial request goes to the Servlet container  which is passed through a standard filter chain. The chain includes the (optional) ActionContextCleanUp filter, which is useful when integrating technologies such as SiteMesh Plugin.  

  Next, the required FilterDispatcher is called, which in turn consults the ActionMapper to  determine if the request should invoke an action.

  If the ActionMapper determines that an Action should be invoked, the FilterDispatcher delegates control to the ActionProxy. The ActionProxy consults the framework   Configuration Files manager (initialized from the struts.xml file).

  Next, the ActionProxy creates an ActionInvocation, which is responsible for the command pattern implementation. This includes invoking any Interceptors (the before clause) in advance of invoking the Action itself.

  Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml. The result is then executed, which often  involves a template written in JSP or FreeMarker to be rendered. While rendering, the templates can use the  Struts tags provided by the framework. Some of those components will work with the ActionMapper to render proper URLs for additional requests.

  Interceptors are executed again (in reverse order, calling the after clause). Finally, the response returns through the filters configured in the web.xml. If the  ActionContextCleanUp filter is present, the FilterDispatcher will not clean up the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present, the FilterDispatcher will cleanup all ThreadLocals.

The goal of Struts2 is to make web development easier for the developer. To achieve this goal Struts2 provides features to reduce XML configuration via intelligent defaults, utilizes annotations and provides conventions over configuration. Actions are now POJOs (Plain Old Java Objects) which increases testability and reduces coupling in the framework, and HTML form field data is converted to proper types for the action to use. Still further decreasing coupling is request processing has been made more modular by allowing a series of interceptors (custom or Struts2 provided) to provide pre-processing and post-processing functionality. Modularity is a common theme a plug-in mechanism provides a way to augment the framework; key classes with the framework can be replaced with custom implementations to provide advanced features not provided out of the box; tags can utilize a variety of different rendering  themes (including custom themes); and there are many different result types available for performing after-action execution tasks which include, but are not limited to, rendering JSPs, Velocity and Freemarker templates. And finally, dependency injection is provided via the Spring Framework plug-in with an option for using Plexus, and work underway for PicoContainer.




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on ; I would like to hear from you :)