Tomcat Principle Chapter

Source: Internet
Author: User

TOMCAT Principle Chapter
One, Tomcat composition (Tomcat consists of the following components)
1.server
A) server is a Catalina servlet container;
b) The Server can contain one or more service components (elements)

2.service
A) The server contains an engine component and one or more connector components;
b) Multiple service configurations can be configured in the server:
1. The first service handles web client requests received by all Tomcat servers;
2. The second service handles web client requests (SSL) that are forwarded over by the Apache server;

3.connector
A) connector belongs to the connection class component;
b) connector is a communication interface between the client and the server, which forwards the client's request to the server and transmits the server's response to the client;

4.engine
A) engine engines belong to the container class components;
b) The container class component mainly deals with customer requests and generates corresponding response results;
c) engine container components handle all customer requests for a specific service component;

5.host
A) The host virtual host component handles all customer requests for a specific virtual host;

6.context
A) Contextual context component processes all customer requests for a particular Web application;

II. Tomcat Structure Directory description (suppose to develop a tomcat project called API, i.e. <catalina_home>/webapps/api)
1./API: #WEB应用的根目录, all the JSP and HTML files are placed in this directory;
2./api/web-inf: #存放web应用的发布描述文件web. xml
3./api/web-inf/class: #存放各种class文件, the servlet class files are also placed in this directory
4./api/web-inf-lib: #存放web应用所需的各种JAR文件


Iii. The individual elements in the Tomcat configuration file are described in
1. Structure relationship of each element
<server>
<service>
<connector>
<eng Ine>
<context>
<context>
</eng Ine>
</connector>
</service>
</server>
2. Description of each element
a) server, service belongs to the top-level element or component
B) connector belongs to the connection element, between the client and the server communication interface, the load will send the customer's request to the server, and the server's response to the customer;
C) engine, Host, context, etc. belong to the container element, A component that primarily processes customer requests and generates corresponding results;
D) the engine container element handles all customer requests for a specific service component;
e) The host container element handles all client requests for a specific virtual host;
F) Context The container element component handles all customer requests for a specific Web application;

Iv. Principle of operation
Combined with the above instructions, analyze how Tomcat server processes an HTTP request to verify how it works
Suppose the request from the customer is: http://localhost:8080/API/notice.jsp

1. When the customer sends the request as shown above, the request is sent to port 8080, where the connector that is listening is obtained;
2.connector gives the request to the engine of the service it is working on and waits for the engine to respond;
3.engine gets the request localhost/api/notice.jsp, matching all the host hosts it owns;
4.engine matches a host named localhost (even if it does not match the request to the host, because the host is defined as the engine's default host);
5.localhost Host obtains the request/api/notice.jsp, matches all the context which it owns;
6.Host matches to the context where the path is/API (if the match is not matched, the request is given to the context of the path named "")
7.path= the context of "/API" to obtain the request notice.jsp, in its mapping table to find the corresponding servlet;
8.context matches to a servlet with a URL pattern of *.jsp, corresponding to the Jspservlet class;
9. Constructs the HttpServletRequest object and the HttpServletResponse object, calls the Jspservlet Doget or Dopost method as the parameter;
10.Context returns the HttpServletResponse object to host after it has finished executing
11.Host return the HttpServletResponse object to the engine
12.Engine return the HttpServletResponse object to connector
13.Connector return the HttpServletResponse object to the customer browser


Tomcat Principle Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.