Tomcat Learning (i)-tomcat structure and process of processing a request

Source: Internet
Author: User

1. Tomcat Fabric Tomcat is a component-based server whose constituent components are configurable, with the outermost component being the Catalina servlet container, and the other components configured in this top-level container in a certain format. The various components of Tomcat are configured in the <tomcat_home>\conf \server.xml file, and the Tomcat server has default implementations for various components by default, and the following is an analysis of the Server.xml file to understand Tomcat How each of the components is organized. The basic composition of the Server.xml file is as follows.

XML configuration file Structure <Server>                      Top class elements: There can be only one <Server> element in a configuration file that can contain multiple service.     <Service>                 top-level class element: it is not a container, it can contain an engine, multiple connector.         <Connector/>         Connector class element: represents the communication interface.            <Engine>   Container class element: Handles all customer requests for a specific service component and can contain more than one host.               <Host>    Container class element: Handles all customer requests for a specific virtual host and can contain multiple context.                  <context >   Container class elements: Handle all customer requests for a specific web app.                &nbsP </Context>                1) The Service service component is a collection of some connector components, which are not itself a container, so components such as logs cannot be defined here. There can be only one engine component in a service component, and multiple connector components may be included.
2) The Connector Component Connector component represents an interface that receives customer requests through this interface, and then sends them to other container components, and finally delivers the server's response to the customer.
3) Engine, host, and context the 3 components described above do not themselves handle customer requests, nor can they generate a response. Only 3 components in Tomcat can handle customer requests and generate responses, and these 3 components are Engine, host, and context components, respectively. These 3 components represent different service scopes, and by nesting relationships you know that the scope of 3 components has the following relationship: Engine>host>context. The A.engine component can contain multiple host components that process all customer requests for a specific service component. B. A host component represents a virtual host, and a virtual host can contain multiple Web applications (context components). The C.context component represents a Web application. Tomcat's various component relationships can be described.

2. Tomcat processes an HTTP request by assuming that the request from the customer is: http://localhost:8080/wsota/wsota_index.jsp 1) The request is sent to the native port 8080, The Coyote http/1.1 Connector, who is listening there, gets 2) connector the request to the engine of the service it is working on, and waits for the response from Engine 3) engine to obtain the request localhost/ wsota/wsota_index.jsp, match all of the virtual hosts that it owns host 4) engine matches to host named localhost (even if it does not match the request to the host processing, Because the host is defined as the engine's default host) 5) localhost host obtains the request/wsota/wsota_index.jsp, matches all of the context 6 it owns) the host matches the path to the/ Wsota context (if the match is not matched to the path named "" context to deal with) 7) path= "/wsota" the context to obtain the request/wsota_index.jsp, in its mapping Find the corresponding servlet in table 8) context matches to a servlet with a URL pattern of *.jsp, corresponding to Jspservlet Class 9) Constructs the HttpServletRequest object and the HttpServletResponse object, calling Jspservlet as a parameter Doget or Dopost method 10) The context returns the HttpServletResponse object to host after the execution is finished) host returns the HttpServletResponse object to engine 12) Engine to return the HttpServletResponse object to connector) connector return the HttpServletResponse object to the customer browser

Java enterprise-Class generic rights security framework source SPRINGMVC MyBatis or Hibernate+ehcache Shiro Druid Bootstrap HTML5

"Java Framework source code download"

Tomcat Learning (i)-tomcat structure and the process of processing a request

Related Article

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.