Struts Flow Diagram Step By Step

This section involves the steps for executing the struts application.

Struts Flow Diagram Step By Step

Struts Flow Diagram Step By Step

In this section we will read about the flow of struts application. Here we will see the architecture of struts with the help of a diagram. We will also describe all the steps involving in executing the application.

In this section we will focus on the Struts 2.X architecture.

Below is the diagram of Struts 2 architecture.

 

In struts application, struts work flow starts with the request, coming from a resource such as JSP page which is going through the standard filter chain to the Servlet container. The standard filter chain includes ActionContextCleanUp, FilterDispatcher.

  • ActionContextCleanUp : In the filter chain ActionContextCleanUp is an optional filter which may be excluded when a request goes to the Servlet container. This filter is mainly used for integrating the other technologies.
  • FilterDispatcher : FilterDispatcher is the next filter of the filter chain from which the request is passing and goes to the Servlet container. This filter is the required filter which uses the ActionMapper to specify whether the Action should be invoked or not.

If the ActionMapper mapped to Action invocation then the FilterDispatcher assigns control to the ActionProxy. An ActionProxy contacted to the configuration file manager named struts.xml and creates an ActionInvocation which implements the command pattern. Then the configured interceptors are invoked by the ActionInvocation

After invoking the Action the ActionInvocation looks up for the appropriate result related with the Action mapped in struts.xml. Then the result is executed which needs rendering of JSP or templates. After executing the result response is returned through the filters configured in the web.xml. In this process interceptors are executed again and clean up operation of ThreadLocal is performed. In the clean up operation the FilterDispatcher checks for the presence of ActionContextCleanUp filter if, it is not present then it cleans up all the ThreadLocals otherwise, it doesn't clean up ThreadLocal ActionContext.

Steps to invoke Struts 2 applications 

Struts 2 Application follows the following steps while executing :

  • Receive Request : In the first step an struts application receives the request from the resource.
  • Maps Action : The request that the struts application receives is passed through a filter chain. In this filter chain a filter FilterDispatcher specifies the Action according to the received request and mapped to the ActionMapper whether the action should be invoked or not.
  • Interceptor Implementation : Once the Action is mapped to the ActionMapper for invoking the action then the FilterDispatcher will assigned the control to the ActionProxy. The ActionProxy will contact to the struts.xml file and creates the ActionInvocation and the ActionInvocation implements the Interceptors.
  • Execution of Action : The interceptors are invoked for processing the common functionalities. After invoking the interceptors ActionInvocation invokes the Action.
  • Rendering Result : If the Action is invoked according to the request received the ActionInvocation searches for the corresponding result of the Action mapped in struts.xml file. And the result is executed which needs rendering of JSP or templates.
  • Return Response : After executing the result response is returned by the filters configured in the web.xml file. In the process return response the interceptors are invoked in reverse order and provide to perform some additional tasks such as clean-up operation.
  • Display Result : At last the control is returned to the Servlet container which shows the output to the browser according to the received response.

For reading more in detail about Struts 2 you may go through the following link http://www.roseindia.net/struts/struts2/