TomCat-01 system architecture

1. The process of the browser accessing the server

Insert picture description here

  1. The user initiates a request to the browser
  2. The browser sends a TCP connection request to the Tomcat server
  3. The Tomcat server receives the request and establishes a connection
  4. The browser generates a data packet in HTTP format
  5. Browser sends request packet
  6. The Tomcat server receives the request packet and parses it
  7. The Tomcat server executes the corresponding request (this step is designed to the specific execution process, which is more important)
  8. Tomcat generates data packets in HTTP format
  9. Send response packet to the browser
  10. The browser parses HTTP packets
  11. The browser presents static data to the user

The browser uses the HTTP protocol to access the server. Http is an application layer protocol
used to define the format of data communication. The specific data transmission uses the TCP/IP protocol.

2. The overall architecture of the Tomcat system

2.1 The process of Tomcat request processing

Insert picture description here
After the HTTP server receives the request, the request is handed over to the Servlet container for processing, and the Servlet container calls the business class through the Servlet interface. The whole set of Servlet interface and Servlet container is called Servlet specification .

Two important identities of Tomcat:

  • http server
  • Tomcat is a servlet container

2.2 Tomcat Servlet container processing flow

When the user requests a URL resource

  1. The HTTP server will encapsulate the request information with the ServletRequest object
  2. Further call a specific Servlet in the Servlet container
  3. In 2., after the Servlet container gets the request, it finds the responding Servlet according to the mapping relationship between URL and Servlet
  4. If the servlet has not been loaded, use the reflection mechanism to create the servlet, and call the init method of the servlet to complete the initialization.
  5. Then call the service method of this specific Servlet to process the request, and the request processing result is encapsulated with the ServletResponse object
  6. Return the ServletResponse object to the HTTP server, and the HTTP server will send the response to the client
    flow chart

2.3 The overall structure of the Tomcat system

From the above, we found that tomcat has two very important functions that need to be completed

  1. Interact with the client browser, perform socket communication, and convert the byte stream and Request/Response objects.
  2. Servlet container handles business logic

Insert picture description here
Tomcat has designed two core components , Connector and Container, to complete the two core functions of Tomcat.

Connector, responsible for external communication : processing Socket connections, responsible for the transformation of network byte streams and Request and Response objects;
container, responsible for internal processing : loading and managing Servlet, and specifically processing Request requests;

Guess you like

Origin blog.csdn.net/weixin_43743650/article/details/114013447