Introduction
A Struts 2 application’s architecture and flow depend on components like ActionMapper, Configuration Manager, Interceptor, Controller, etc.
In the following article, we will learn about the Struts 2 architecture in detail.
Struts 2 Architecture and flow
Here, we are going to understand the struts flow in two ways:
- struts 2 basic flow
- struts 2 standard architecture and flow provided by apache struts
Struts 2 basic flow
Let's understand the basic flow of struts 2 application using the figure given below-
- The user submits an action request.
- The Controller triggers ActionInvocation.
- ActionInvocation calls each interceptor and action.
- There is a result.
- The ActionInvocation receives the outcome as a response.
- It produces a HttpServletResponse.
- An answer is delivered to the user.
Struts 2 standard flow (Struts 2 architecture)
Let's understand the basic architecture of the struts 2 application using the figure given below-
-
The user submits an action request.
-
The container translates the request in the web.xml file and obtains the Controller's class name.
-
The Controller is called by the container (StrutsPrepareAndExecuteFilter or FilterDispatcher). It is StrutsPrepareAndExecuteFilter as of struts 2.1. It was FilterDispatcher prior to 2.1.
-
ActionMapper provides the information to the Controller for the action.
-
The Controller calls ActionProxy.
-
From the configuration manager, which receives its data from the struts.xml file, ActionProxy obtains information about the action and interceptor stack.
-
The request is forwarded to the ActionInvocation by ActionProxy.
-
ActionInvocation launches each interceptor and action.
-
There is a result.
-
The ActionInvocation receives the outcome as a response.
- It produces a HttpServletResponse.