What’s in Tomcat?

Most of the time, language can not reflect a thing more intuitively without pictures, so directly above In case I can’t understand one, I put two, the picture is found on the Internet, hahaha

It can be seen that the outermost layer of Tomcat is a server container, which can contain multiple services. In this way, it can provide us with multiple services. Then, each service contains multiple connectors. We can almost guess their function from the meaning of two wordsCopy the code

The Connector,

It is used to receive requests and encapsulate them into Request and Response for specific processing. At the bottom layer, Socket is used to connect. Connector implements both TCP/IP and HTTP (request, response).

How does a Connector handle a requestA ProtocolHandler is a core component of Connector. This is a ProtocolHandler. When I go to Baidu Translate to check the pronunciation of this word, I am prompted to type it in Spanish. Different protocolHandlers represent different connection types, for example, Http11Protocol uses normal sockets for connections, and Http11 NioProtocol uses NioSockets for connections. The ProtocolHandler consists of three important components: Endpoint, Processor, and Adapter.

The Endpoint processes the network connection of the underlying Socket. The Processor encapsulates the Socket received by the Endpoint into a Request, and the Adapter sends the encapsulated Request to the Container for processing.Copy the code

That is, the Endpoint implements the TCP/IP protocol, and the Processor implements the HTTP protocol. The Adapter submits requests to the container

The Container,

Let’s cut the crap and look at the structure firstContainer has four main sub-containers: Engine, Host, Context, and Wrapper.

An Engine Host is used to manage multiple sites. A Service can have at most one Engine Host. Represents an application localhost/test, corresponding to a program you normally develop, or a Web-INF directory and the following web. XML file Wrapper: each Wrapper encapsulates a ServletCopy the code

We would appreciate it if you could point out any mistakes