How Tomcat works, how tomcat works
1-components of Tomcat Server
1.1-Server
A Server element represents the entire Catalina servlet container. (Singleton)
1.2-Service
A Service element represents the combination of one or more Connector components that share a single Engine
A Service is a collection composed of one or more ctor s and an Engine that processes customer requests obtained by all Connector S.
1.3-Connector
A Connector listens to customer requests on a specified port, sends the obtained requests to the Engine for processing, obtains responses from the Engine, and returns the customer
TOMCAT has two typical ctor, one directly listening for http requests from browser and the other listening for requests from other webservers.
Coyote Http/1.1 Connector listens for http requests from the client browser at port 8080
Coyote JK2 Connector listens to servlet/jsp proxy requests from other WebServer (Apache) at Port 8009
1.4-Engine
The Engine element represents the entire request processing machinery associated with a participant Service
It has es and processes all requests from one or more Connectors
And returns the completed response to the Connector for ultimate transmission back to the client
Multiple Virtual hosts can be configured in the Engine. Each Virtual Host has a domain name.
When the Engine obtains a request, it matches the request to a Host, and then delivers the request to the Host for processing.
The Engine has a default virtual Host. When the request cannot match any Host, the default Host is used for processing.
1.5-Host
Represents a Virtual Host. Each Virtual Host matches the Domain Name of a network Domain.
Deploy one or more Web apps under each virtual host. Each Web App corresponds to a Context and has a Context path.
When the Host receives a request, it matches the request to a Context, and then sends the request to the Context for processing.
The matching method is "Longest match", so a Context with path = "" will become the default Context of the Host.
All requests that cannot match other Context path names 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 load the Servlet class according to the configuration file $ CATALINA_HOME/conf/web. xml and $ WEBAPP_HOME/WEB-INF/web. xml at creation
When the Context obtains the request, it searches for the matching Servlet class in its own mapping table.
If yes, this class is executed to obtain the request response and return
2-Tomcat Server structure
3-Description of the configuration file $ CATALINA_HOME/conf/server. xml
This file describes how to start Tomcat Server
4-Description of the deployment configuration file web. xml of Context
A Context corresponds to a Web App. Each Web App is composed of one or more servlets.
When a Web App is initialized, it loads each servlet class defined in "deployment configuration file web. xml" with its own ClassLoader object.
It first loads the servlet class deployed in $ CATALINA_HOME/conf/web. xml.
Then load the servlet class deployed in the WEB-INF/Web. xml under the root directory of your web App
The web. xml file has two parts: servlet class definition and servlet ing definition.
Each loaded servlet class has a name and is filled in with the mapping table of the Context, which corresponds to a url pattern.
When the Context obtains the request, it queries the mapping table, finds the requested servlet, and executes the request to obtain the request response.
Analyze all the web. xml files shared by Context, and the servlet defined in it is loaded by all Web apps.
5-Tomcat Server processes an http request
Assume that the request from the customer is:
Http: /localhost: 8080/wsota/wsota_index.jsp