Client users click on the browser service to connect , The browser transmits messages through routing through the underlying services of the client , The target server gets the parsing message ,Tomcat The listener triggers the processing request
One 、Tomcat Software directory structure and function
bin： Service related scripts , for example ： start-up 、 Shut down, etc
conf： Store different configuration files , Columns such as ：server.xml、web.xml
lib： tomcat Run the required library files
logs： Running log files
webapps： web The root of the deployment
work ： Deposit jsp The compiled class file
Two 、server Analyze the system structure
Provide an interface for other programs to access this Service aggregate 、 At the same time, maintain all that it contains Service Life cycle of , Including how to initialize 、 How to end the service 、 How to find what others want to visit Service
service yes server The next collection ,service Containing multiple receiving requests connector And there's a container that handles all connections container
connector It is used to listen for client requests , And encapsulate and submit the request container Handle , Then the processing results are returned to the client
tomcat There are two typical connector, A browser monitor http, The other is to monitor webservice
Coyote Http/1.1 Connector In the port 8080 Listening from customers browser Of http request
Coyote AJP/1.3 Connector In the port 8009 Listening from others WebServer(Apache) Of servlet/jsp Agent request
Engine You can configure multiple virtual hosts Virtual Host, Each virtual host has a domain name
When Engine When getting a request , It matches the request to some Host On , Then give the request to the Host To deal with it
Engine There is a default virtual host , When the request can't match any of them Host Last time , Will be given to the default Host To deal with it
Representing one Virtual Host, Virtual host , Each virtual host and a network domain name Domain Name Match
Each virtual host can be deployed (deploy) One or more Web App, Every Web App Corresponds to a Context, There is one Context path.
When Host When getting a request , The request will be matched to some Context On , Then give the request to the Context To deal with it .
The way to match is “ The longest match ”, So a path=="" Of Context Will become the Host Default Context.
All can't and other Context All requests that match the pathname will end up with the default Context matching .
One Context Corresponds to a Web Application, One Web Application By one or more Servlet form .
Context It will be created according to the configuration file WEBAPP_HOME/WEB-INF/web.xml load Servlet class .
When Context When you get a request , Will be in their own mapping table (mapping table) Looking for a match in Servlet class , If you find , The class is executed , Get a response to a request , And back to .
5、Context Deployment profile for web.xml Explanation
One Context Corresponds to a Web App, Every Web App It's made up of one or more servlet Composed of
When one Web App When it is initialized , It will use its own ClassLoader Object loading “ Deployment profile web.xml” Each of the servlet class
It is first loaded in $CATALINA_HOME/conf/web.xml Deployed in servlet class
Then load it in your own Web App In the root directory WEB-INF/web.xml Deployed in servlet class
web.xml The document has two parts ：servlet Class definition and servlet Mapping definition
Every loaded servlet Classes have a name , And be filled in with Context Mapping table (mapping table) in , And some kind of URL PATTERN Corresponding
When it's time to Context When you get a request , Will query mapping table, Find the requested servlet, And execute to get a response to the request
Analyze all the Context Shared web.xml file , Defined in it servlet By all the Web App load
3、 ... and 、 Example
Tomcat Server Deal with one http Process of request
Suppose the request from the customer is ：
The request is sent to the local port 8080, I was listening there Coyote HTTP/1.1 Connector get
Connector Give the request to the Service Of Engine To deal with it , And wait for it to come from Engine The response of the
Engine Get the request localhost/wsota/wsota_index.jsp, Match all the virtual hosts it owns Host
Engine Match to name localhost Of Host（ Give the request to the Host Handle , Because it's time to Host Is defined as the Engine The default host for ）
localhost Host Get the request /wsota/wsota_index.jsp, Match all it has Context
Host Match to path /wsota Of Context（ If it doesn't match, give the request to the pathname "" Of Context To deal with ）
path="/wsota" Of Context Get the request /wsota_index.jsp, In its mapping table Search for the corresponding servlet
Context Match to URL PATTERN by *.jsp Of servlet, Corresponding to JspServlet class
structure HttpServletRequest Objects and HttpServletResponse object , Call... As a parameter JspServlet Of doGet or doPost Method
Context After the execution HttpServletResponse Object returned to Host
Host hold HttpServletResponse Object returned to Engine
Engine hold HttpServletResponse Object returned to Connector
Connector hold HttpServletResponse Object returned to customer browser