Tomcat is widely known as a web container. It has accompanied my entire programming career, from the time I started learning Java to my current work. Tomcat is essentially a Servlet container. What a Servlet can do is: process request resources and fill in response objects for the client. Tomcat is responsible for loading the Servlet class we wrote, calling the Servlet's init() method, creating a servletRequest and a servletResponse instance for a request, calling the servlet's service() method, passing the servletRequest and servletResponse as parameters, and calling destroy() to uninstall the servlet when closing it. Next, I will briefly introduce the overall structure of Tomcat. Tomcat's overall structure As shown in the figure, the two main components of Tomcat are the connector and the container. Multiple connectors and a container form a service. The service is used to provide services to the outside world, and the life cycle of the service is controlled by the server. Server belongs to the top-level abstraction. The connector is used to handle things related to network connections, such as socket connections, request encapsulation, connection thread pools, etc. The container mainly handles the requests accepted by the connector. Service is just an extra layer around Connector and Container, assembling them together to provide services to the outside. A Service can have multiple Connectors but can only have one Container. The lifecycle of all components is managed uniformly using the lifecycle interface, which includes init, start, stop, and destroy methods. The original connector could only be set to BIO mode. Now the default connection mode of high-level Tomcat versions is NIO, which greatly improves the concurrency of requests. There are four types of containers in Tomcat, from top to bottom: engine, host, context, and wrapper. A wrapper corresponds to a servlet, a context corresponds to an application, a host corresponds to a site, and an engine is an engine. There is only one container. The startup between containers is done using Tomcat container model This is a brief introduction to the entire structure of Tomcat. Next, we will deepen our understanding through the processing flow of a Tomcat request. Assuming the request is: http://localhost:8080/test/index.jsp, the processing flow of Tomcat is as follows 1. The request is sent to port 8080 and is received by the connector. 2. The connector passes the request to the engine of its service for processing and waits for the engine to respond. 3.engine obtains the request address and matches the virtual host host 4. The engine matches the host named localhost, which receives the request /test/index.jsp, matching the context owned by the host 5. The host matches the context with path /test. If no match is found, it is handled by the empty context. 6. The context gets the request/index.jsp and looks for the corresponding servlet in the mapping file 7. The context matches the servlet with the pattern *.jsp and finds the corresponding JspServlet class (Jsp will eventually be converted into Servlet) 8. Construct httpservletrequest and httpServletResponse objects and use them as parameters to call doGet or doPost of JspServlet 9.context returns the response to the host 10. The host returns the response to the engine 11. The engine returns the response to the connector 12. The connector returns the response to the user's browser, and the request ends The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Java imports data from excel into mysql
>>: An Incomplete Guide to JavaScript Toolchain
This article shares the specific code of JavaScri...
CSS 3 animation example - dynamic effect of Tab b...
Table of contents summary Basic Example motivatio...
Platform deployment 1. Install JDK step1. Downloa...
As a technical novice, I am recording the process...
Related article: Beginners learn some HTML tags (1...
Table of contents First of all, you need to know ...
Many people now live on the Internet, and searchin...
introduction Have you ever encountered a situatio...
Table of contents history pushState() Method push...
Part.0 Background The company's intranet serv...
Table of contents 1. What is a calculated propert...
Table of contents 1. What is Promise 2. Basic usa...
Since I usually use the docker build command to g...
Table of contents 1. Vue Overview Vue official we...