Most of the materials are summaried from <Struts 2 in Action>
1. The MVC designing pattern in Struts 2 are implemented by Action – Model, Result – View and FilterDispatcher – Controller
1) Controller – FilterDispatcher
The controller’s job is to map requests to actions. FilterDispatcher is a servlet filter that inspects each incoming request to determine which Struts 2 action should handle the request. The framework handles all of the controller work for you, you just need to inform the framework which request URLs map to which of your actions. You can do this with XML-based configuration files or Java annotations.
2) Model – Action
Model is the internal state of the application. This state is composed of both the data model and the business logic. A Struts 2 action serves two roles, first is an encapsulation of the calls to business logic into a single unit of work, and second is a locus of data transfer.
3) View – Result
View is the presentation component of the MVC pattern; it translates the state of the application into a visual presentation with which the user can interact.
2. How it works
1) Interceptors
Interceptors are invoked both before and after the action, though we should note that they actually fire after the result has executed. The interceptor allows common, cross-cutting tasks to be defined in clean, reusable components that you can keep separate from your action code.
2) Value Stack
A storage area that holds all of the data associated with the processing of a request. Struts 2 uses the Value Stack as a storage area for all application domain data which will be needed during the processing of a request. Data is moved to the Value Stack in preparation for request processing, it is manipulated there during action execution, and it is read from there when the results render their response pages.
3) OGNL
OGNL is the tool that allows us to access the data we put in that central repository. It is an expression language that allows you to reference and manipulate the data on the Value Stack.
4) Action Context
The Action Context contains all of the data that makes up the context in which an action occurs. This includes the Value Stack but also includes stuff the framework itself will use internally, such as the request, session, and application maps from the Servlet API. The use of ThreadLocal makes the Action Context, and thus the Value Stack, accessible from anywhere in the same thread of execution. Since Struts 2’s processing of each request occurs in a single thread, the Value Stack is available from any point in the framework’s handling of a request.