Sturts 2 MVC framework contains the following core components:
- Actions.
- Interceptors.
- Value Stack / OGNL
- Result types
Diagram:
Struts 2 request life cycle:
- When a request comes web container maps the request in the web.xml and calls the controller (FilterDispatcher).
- FilterDispatcher calls the ActionMapper to find an Action to be invoked.
- FilterDispatcher calls the ActionProxy.
- ActionProxy reads the information of action and interceptor stack from configuration file using configuration manager (struts.xml) and invoke the ActionInvocation.
- ActionInvocation calls the all interceptors one by one and then invoke the action to generate the result.
- action is executed ActionInvocation again calls the all interceptors in reverse order.
- Control is returned to the FilterDispatcher.
- Result is sent to the client.
Note: Struts 2 uses the ActionContext to store all the data for a request processing. ActionContext work on the ThreadLocal concept i.e. unique values for every thread. That’s why it is thread safe and we don’t have to make our action thread safe explicitly.
Next Topic: Struts 2 Configuration Files.
Previous Topic: Struts 2 overview.