Struts2 core workflow and principles

Source: Internet
Author: User
Struts2 is a powerful open-source Java Web framework and a pojo-based action MVC Web framework. Struts 2 takes webwork as the core and uses an interceptor mechanism to process user requests. This design also enables the business logic controller to completely remove from the servletapi, therefore, Struts 2 can be understood as a webwork update product.


 

It comes from the official site of struts2 and is the overall structure of struts 2.
The process of a request in the struts2 framework is roughly divided into the following steps:
1. The client initializes a request pointing to a servlet container (such as Tomcat ).
2. This request goes through a series of filters (these filters have an optional filter called actioncontextcleanup, which is very helpful for the integration of struts2 and other frameworks, such as sitemesh plugin)
3. filterdispatcher is called. filterdispatcher asks actionmapper to determine whether to call an action.
4. If actionmapper decides to call an action, filterdispatcher submits the request processing to actionproxy.
5. actionproxy asks the framework configuration file through Configuration Manager and finds the action class to be called.
6. actionproxy creates an actioninvocation instance.
7. The actioninvocation instance uses the naming mode for calling. Before and after the action is called, the call of the relevant Interceptor (intercepter) is involved.
8. Once the action is executed, actioninvocation is responsible for finding the corresponding return result based on the configuration in struts. xml. The returned result is usually a JSP or freemarker template to be represented (but not always, or another action chain. You can use the tag inherited from the struts2 framework in the Process of representation. Actionmapper needs to be involved in this process
 
All objects (actions, results, interceptors, etc.) in the above process are created through objectfactory.

The difference between the interceptor and the filter is described here:

1. the interceptor is based on the Java reflection mechanism, and the filter is based on function callback.
2. The filter depends on the servlet container, while the interceptor does not depend on the servlet container.
3. the interceptor can only work on Action requests, while the filter can work on almost all requests.
4. the interceptor can access objects in the Action context and value stack, but the filter cannot.
5. In the lifecycle of an action, the interceptor can be called multiple times, and the filter can only be called once during container initialization.





Struts2 core workflow and principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.