In the previous section we learned about MVC framework and in this section we will learn about the different components of Struts 2 framework.In the previous section we learned about MVC framework and in this section we will learn about the different components of Struts 2 framework.
Struts 2 Framework Architecture
In the previous section we learned about MVC framework and in this section we will learn about the different components of Struts 2 framework.
How Struts 2 Framework works?
Suppose you are accessing the product list page in a Struts 2 shopping cart application and typing <your-domain/showproducts.action> to get the list of all the products available for purchase. In any Struts 2 application *.action is the default mapping configured in web.xml file. Suppose the name of the action is showpoducts.action, which retrieves the data from the model (database) and displays on the browser. In this scenario the request processing steps can be summarized into blow mentioned steps:
Following diagram shows the high level architecture of Struts 2 Framework:
Detailed Architecture of Struts 2 Framework
Following diagram shows the detailed architecture of Struts 2 Framework.
The above diagram depicts the architecture of Struts 2 Framework. Following diagram shows that the initial request goes to the servlet container, which is then passed through standard filer chain.
The filter chain includes:
1. Action ContextCleanUp filter: The ActionContextCleanUp filter is optional and it is useful when integration has to be done with other technologies like SiteMash Plugin.
2. FilterDispatcher: Next the FilterDispatch is called, which in turn uses the ActionMapper to determine weather to invoke an Action. If the action is required to be invoked, the FilterDispatcher delegates the control to the ActionProxy.
3. ActionProxy: The ActionProxy takes the help from Configuration Files manager, which is initialized from the struts.xml. Then the ActionProxy creates an ActionInvocation, which implements the command pattern. The ActionInvocation process invokes the Interceptors (if configured) and then invokes the action. The ActionInvocation looks for proper result. Then the result is executed, which involves the rendering of JSP or templates.
Then the Interceptors are executed again in reverse order. Finally the response returns through the filters configured in web.xml file. If the ActionContextCleanUp filter is configured, the FilterDispatcher does not clean the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present then the FilterDispatcher will cleanup all the ThreadLocals present.
Struts 2 Core components
Struts 2 Core components are Action handler, Result Handler and Custom Tags.
We will learn about these core components in the future lessons.