Struts 2 Framework
Struts 2 Framework
Struts 2 is a pull-MVC framework. i.e. the data that is to be displayed to user has to be
pulled from the Action.
Architecture of Struts 2
Struts 2 Architecture is based on WebWork 2 framework. It leverages
the standard JEE technologies such as Java Filters, JavaBeans,
ResourceBundles, Locales, XML etc in its architecture.
Following is its framework diagram.
Image Courtesy: struts.apache.org
1. The normal lifecycle of struts begins when the request is sent from
client. This results invoke the servlet container which in turn is
passed through standard filter chain.
2. The FilterDispatcher filter is called which consults the ActionMapper to
determine whether an Action should be invoked.
3. If ActionMapper finds an Action to be invoked, the FilterDispatcher delegates
control to ActionProxy.
4. ActionProxy reads the configuration file such as struts.xml. ActionProxy creates
an instance of ActionInvocation class and delegates the control.
5. ActionInvocation is responsible for command pattern implementation.
It invokes the Interceptors one by one (if required) and then invoke
the Action.
6. Once the Action returns, the ActionInvocation is responsible for looking up the
proper result associated with the Action result code mapped in struts.xml.
7. The Interceptors are executed again in reverse order and the response is returned
to the Filter (In most cases to FilterDispatcher). And the result is then sent to the
servlet container which in turns send it back to client.
Struts 2 comes with highly configurable AJAX tag library which can
be used directly without writing JavaScript code. Struts 2 also support
Dojo library. Its now very easy to add AJAX enabled feature such as Autocomplete to
your web application.
Related: Introduction to DOJO Toolkit