STRUTS2 architecture analysis and operation mechanism

Source: Internet
Author: User

Example Analysis

1. After entering the URL address in the browser, the HTTP protocol will be sent to Tomcat,tomacat to see which access is received after the request

WebApplication (e.g. struts2_0100_introduction), Tomcat gives struts2_0100_introduction to the corresponding

WebApplication program to deal with.



2. Then refer to the corresponding Web. xml file under Struts2_0100_introduction and submit the request to struts2filter for processing



("/*" for all files in this project, all project requests will be captured)
3.filter calls Dofilter, reference Struts.xml

(1) When referring to Struts.xml, the first reference is namespace(2) then find the corresponding action(3) find the corresponding result(4) when the corresponding result is found, the corresponding request will be given to the JSP file.(5) JSP file feeds the content to the client


Struts2 operating mechanism


You can see that a request is handled in STRUTS2 as follows:

1. The client initializes a request to the servlet container (for example, Tomcat);

2. This request passes through a series of filters (filter) with an optional filter called Actioncontextcleanup, which filters are useful for integration of Struts2 and other frameworks, for example: Sitemesh Plugin);

3, then Filterdispatcher is called, Filterdispatcher asked Actionmapper to decide whether the request needs to invoke an action;

4, if Actionmapper decided to call a action,filterdispatcher to the processing of the request to actionproxy;

5, Actionproxy through the configuration Manager to ask the framework profile, find the action class that needs to be called;

6. Actionproxy create an instance of Actioninvocation.

7, the Actioninvocation instance uses the naming pattern to invoke, before and after calling the action procedure, involves the related interceptor (Intercepter) the tune use.

8. Once the action is executed, Actioninvocation is responsible for finding the corresponding return result according to the configuration in the Struts.xml. The return result is usually (but

Not always, may be another action chain) a template that needs to be represented by a JSP or Freemarker. In the process of presentation, you can use

Struts2 The tags inherited in the framework. In this process, it is necessary to involve actionmapper.

Core Controller
Filterdispatcher is the early struts2 of the filter, the latter are used strutsprepareandexecutefilter, such as 2.1.6, 2.1.8.

Strutsprepareandexecutefilter name has been very good to explain the problem, prepare and execute, the former express preparation, can be said to refer to the filter

Init method, that is, a prepared import, the latter means to filter, refers to the Dofilter method, will request requests, forwarded to the corresponding action to deal with.

You can split him into Strutspreparefilter and strutsexecutefilter, and we can add our own filters between the two filters.

Device.! Strutsprepareandexecutefilter is the core of the controller, which is the core of the control Layer (Controller) in the implementation of the Struts 2 of MVC.


Three initialization parameters:

1. config parameter: Specifies the configuration file to load. Comma split.

2. Actionpackages parameter: Specifies the package space where the action class resides.   Comma split.  

3, configproviders parameter: Custom profile provider, need to implement Configurationprovider interface class. Comma split.

Think about why this is so troublesome, in the middle of going through a transit?

Separate the request from the result (view), and it is more flexible to replace the results with a different view. It's like my MVC.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

STRUTS2 architecture analysis and operation mechanism

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.