Tomcat startup analysis

zhaozj2021-02-16  148

1 - Component of Tomcat Server

1.1 - Server

A Server Element Represents The Entire Catalina Servlet Container. (Singleton)

1.2 - service

A Service Element Repens The Combination of One or more Connector That Share A Single EngineService is a collection: it consists of one or more Connector, and an Engine, which is responsible for processing all the customer requests obtained by Connector.

1.3 - Connector

A Connector will listen to the customer request on a specified port, and will give the request to Engine to process, get a response from Engine and return to customer Tomcat has two typical Connector, a direct listening from Browser HTTP request A request COYOTE HTTP / 1.1 COYOTE HTTP / 1.1 Connector at the port 8080 at the port 8080 HTTP request COYOTE JK2 Connector in port 8009 SERVLET / JSP proxy request from other WebServer (Apache)

1.4 - ENGINE

The Engine element represents the entire request processing machinery associated with a particular ServiceIt receives and processes all requests from one or more Connectorsand returns the completed response to the Connector for ultimate transmission back to under the clientEngine can configure multiple virtual hosts Virtual Host, each Both the virtual host has a domain name when Engine gets a request, matches the request to a host, then handed the request to the host to handle ENGINE has a default virtual host, when the request cannot match to any host At the time, it will be handed over to the default host.

1.5 - Host

On behalf of a Virtual Host, a virtual host, each virtual host, and a network domain name Domain Name matches each virtual host, you can deploy (deploy) one or more web apps, each web app corresponds to a context, there is a Context path When the Host gets a request, the request is matched to a context, then handed over to the context to handle the matching method is "longest match", so a path == "" Context will Become a request for the default Context that cannot be matched with the path name that cannot be and other contexts, will eventually match the default context

1.6 - context

A Context corresponds to a web application, a web application consists of one or more servlets Context will be based on the configuration file $ CATALINA_HOME / CONF / Web.xml and $ WebApp_home / Web-INF / Web.xml to load servlet classes When Context gets a request, you will find the matching servlet class in your own mapping table (mapping table) if you find it, then execute this class, get the response of the request, and return

2 - Structure of Tomcat Server

3 - Configuration File $ CATALINA_HOME / conf / server.xml Description This file describes how to start Tomcat Server

Waiting at the port 8005 waiting to close the command

If you accept the "shutdown" string, turn off the server.

->

I haven't seen this here.

->

I haven't seen this here, I will go first.

->

... ...

"- Tomcat Standalone Service

Service is a set of Connector's collection

They share a request to process all requests received by Connector

->

ClassName: The implementation class of the Connector is org.apache.coyote.tomcat4.coyoteconnector

Port: In the port number 8080, the HTTP1.1 request from the customer Browser is listened.

MINPROCESSORS: This Connector first creates 5 thread waiting for the customer request, each request is responsible by a thread

MaxProcessors: When the existing thread is not enough service customer request, if the total number of threads is less than 75, create a new thread to process the request.

Acceptcount: When the existing thread has reached the maximum number 75, ask the customer to queue

When the number of requests in the queue exceeds 100, the later request returns a Connection Refused error.

Redirectport: When the customer request is HTTPS, forward the request to the port 8443

Other attributes

->

Port = "8080"

MINPROCESSORS = "5" maxprocessors = "75" acceptcount = "100"

Enablelookups = "True"

REDIRECTPORT = "8443"

Debug = "0"

ConnectionTIMEOUT = "20000"

Useurivalidationhack = "false"

DisableUploadTimeout = "true" />

It will match the request and your own virtual host, and transfer the request to the corresponding Host to process

The default virtual host is Localhost

->

AppBase: The root directory of the virtual host is WebApps /

It will match the request and its own CONTEXT path, and transfer the request to the corresponding context to process

->

PATH: The path name of this context is "", so the context is the default context of the Host.

DOCBASE: The root of this Context is WebApps / MyContext /

->

4 - Context Deployment Profile Web.xml

A Context corresponds to a web app, each web app consists of one or more servlet When a web app is initialized, it will load "Deployment Profile Web.xml" in its own ClassLoader object. Each servlet class is first loaded in the servlet class deployed in $ catalina_home / conf / web.xml and loads the servlet class web.xml file depicted in the Web-INF / Web.xml of our Web App root. There are two parts: servlet class definitions and servlet mapping defines that each loaded servlet class has a name and is filled in the Mapping table, and some URL Pattern corresponds to requests for this context. When you query mapping table, find the requested servlet, and execute to get a request to respond to analyze all the web.xml files that are shared in it, in which servlets are loaded by all Web App.

This file is a shared deployment profile shared by all Web App,

Whenever a web app is deployed, the file will be processed first, and then the web app is our own /Web-inf/web.xml

->

When the user's HTTP request cannot match any servlet, the servlet is executed.

URL PATTERN MAPPING: /

->

Default

Org.apache.catalina.servlets.defaultServlet

debug

0

Listings

True

1

Handling anonymous servlet in a web app

When a servlet is written and compiled into / web-inf / classes /, it is not defined in /Web-inf/web.xml.

The servlet is called to map anonymous servlet into the form of / servlet / classname.

URL PATTERN MAPPING: / servlet / *

->

Invoker

Org.apache.catalina.servlets.invokerseervlet

debug

0

2

When the request is a JSP page (* .jsp) the servlet is called

It is a JSP compiler that compiles the requested JSP page into a servlet and execute.

URL PATTERN MAPPING: * .JSP

->

JSP

org.apache.jasper.servlet.jspservlet

logverbositylevel

Warning

3

Default

/

Invoker

/ servlet / *

JSP

*. jsp

... ...

5 - Tomcat Server Process Process Process Hypothesis Procedures for HTTP Requests To: http: // localhost: 8080 / wsota / wsota_index.jsp

1) Requests to be sent to the local port 8080, which is listened to the COYOTE HTTP / 1.1 Connector to get 2) Connector handles the request to the service of the service to process, and wait for response from Engine 3) Engine Request localhost / wsota / wsota_index.jsp, matches all of its virtual host host4) Engine matches Host-called LocalHost (even if it does not assign the request to the HOST process, because the Host is defined as the engine Default Host) 5) LocalHost Host Get Request / Wsota/wsota_index.jsp, match all of its context6) Host matches the path to the path to / wsota (if you do not give the request to the path name " Context deduction) 7) Path = "/ wsota" Context get request / wsota_index.jsp, looking for the corresponding servlet8 in its mapping table) Context matches the servlet of the URL Pattern * .jsp, corresponding to the JSPSERVLET class 9) configuration HttpServletRequest object and HttpServletResponse objects, as calling JspServlet the doGet or doPost method 10) Context the HttpServletResponse object after execution of finished back to Host11) Host the HttpServletResponse object back to the Engine12) Engine the HttpServletResponse object back to the Connector13) Connector the HttpServletResponse object Return to the customer Browser

转载请注明原文地址:https://www.9cbs.com/read-8527.html

New Post(0)