On the principle of Tomcat

Source: Internet
Author: User
Tags tomcat server

1, the composition of Tomcat server principle

(1)-Server

A server represents the entire Catalina servlet container.

(2)-service

A service is a collection that consists of one or more connector, as well as a engine, responsible for handling the client requests obtained by all connector.

(3)-connector

A connector listens on a client request on a specified port and assigns the requested request to engine for processing, receiving a response from the engine and returning it to the customer.

Tomcat has two typical connector, one listens directly to HTTP requests from browser, and one listens for requests from other webserver.

(4)-engine

Engine has a default virtual host that will be handled by the default host when the request cannot be matched to any host.

(5)-host

Represents a virtual host, which matches each virtual host and a network domain name Domain name. One or more web apps can be deployed under each virtual host, and each web app corresponds to a context and has a path. When the host obtains a request, it matches the request to a context and then hands the request to the context for processing.

(6) Context

A context corresponds to a Web application, and a Web application has one or more servlet components. When created, the context loads the servlet classes according to the configuration files $catalina_home/con/web.xml and $webapp_home/web-inf/web.xml. When the context gets the request, it looks for a matching servlet class in its own mapping table. If found, executes the class, gets the requested response, and returns.

The process of Tomcat Server processing an HTTP request

Suppose a request from a customer

http://localhost:8080/wsota_index.jsp

1 requests are sent to native port 8080, where the connector that is listening is obtained

2Connector Engine the request to the service in which it resides and waits for a response from engine

3Engine GET request localhost/wsota_index.jsp, match all the virtual host host it owns

4Engine accompany to host named localhost

5localhost host gets the request/wsota_index.jsp to match all the context it owns

6Host match to the context where the path is/wsota (if the match is not matched, give the request to the context of the path named "")

The context of the 7path= "/wsota" obtains the request/wsota_index.jsp, looking for the corresponding servlet in its mapping table

8Context matching servlet to URL pattern *.jsp, corresponding to Jspservlet class

9 Constructing HttpServletRequest objects and HttpServletResponse objects, calling Jspservlet Doget or Dopost methods as parameters

10Context returns the HttpServletResponse object after execution to the host.

11Host returns the HttpServletResponse object to engine

12Engine returns the HttpServletResponse object to connector

13Connector returns the HttpServletResponse object to the customer browser.

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.