How Tomcat works

Source: Internet
Author: User

Components of the 1-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 a. Share a single Engine
A service is a collection that consists of one or more connector, and an engine that handles all customer requests received by connector.

1.3-connector

A connector will listen for the customer request on a specified port and give the request to the engine to process, receive a response from the engine and return to the customer
Tomcat has two typical connector, one that listens directly to HTTP requests from browser, and one that listens for requests from other webserver
Coyote http/1.1 Connector listens for Http requests from customer browser at port 8080
Coyote JK2 Connector listens for 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 particular Service
It receives and processes all requests from one or more connectors
and returns the completed response to the Connector for ultimate transmission back to the client
The engine can be configured with multiple virtual hosts, each hosting a domain name
When the engine obtains a request, it matches the request to a host and then gives the request to the host to handle
The engine has a default virtual host that, when the request cannot be matched to any host, is given to the default host for processing

1.5-host

Represents a virtual host, which matches each virtual host with a network domain name
One or more web apps can be deployed under each virtual host, each Web app corresponds to a context with a context path
When host obtains a request, it matches the request to a context and then gives the request to the context to process
The matching method is "longest match", so a path== "" context will be the default context for that host
All requests that cannot match the path names of other context will eventually match that default context

1.6-context

A context corresponds to a Web application, and a Web application consists of one or more servlets
The context will be loaded into the Servlet class based on the profile $catalina_home/conf/web.xml and $webapp_home/web-inf/web.xml when it is created
When the context obtains the request, it looks for the matching servlet class in its own mapping table (mapping table)
If found, executes the class, obtains the requested response, and returns

2-tomcat server's structure diagram

3-Description of the configuration file $catalina_home/conf/server.xml
This file describes how to start the deployment configuration file for the Tomcat server

4-context Web. config
A context corresponds to a web app, where each web app is made up of one or more Servlets
when a web app is initialized, it loads its own ClassLoader object into the deployment configuration file Web. xml Each servlet class that is defined in
It first loads the servlet class deployed in $catalina_home/conf/web.xml
and then loads it into its own web app root directory web-inf/ The servlet class
Web. xml file deployed in Web. XML has two parts: the servlet class definition and the servlet mapping definition
Each loaded servlet class has a name and is populated with the context's mapping table (mapping table), and a URL pattern corresponding to
when the context obtains the request, it queries mapping table, finds the requested servlet, and executes to obtain the request response

Analyze all the context-shared web. xml files, where the servlet defined in it is loaded by all Web apps into

5-tomcat Server processes an HTTP request
assumes the request from the customer is:
http ://localhost:8080/wsota/wsota_index.jsp

    1. The request is sent to the native port 8080, where the Coyote http/1.1 connector that is listening is obtained
    2. Connector the request to the engine of the service it is working on and waits for a response from the engine
    3. The engine gets the request localhost/wsota/wsota_index.jsp, matching all the virtual host hosts it owns
    4. The engine matches the 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 gets the request/wsota/wsota_index.jsp, matching all the context it owns
    6. The host matches to the context where the path is/wsota (if it does not match the request to the context where the path name "" is processed)
    7. The context of the path= "/wsota" obtains the request/wsota_index.jsp, looking for the corresponding servlet in its mapping table
    8. Context matches to a servlet with a URL pattern of *.jsp, corresponding to the Jspservlet class
    9. Constructs a HttpServletRequest object and HttpServletResponse object, calling the Doget or Dopost method of Jspservlet as a parameter
    10. Context returns the HttpServletResponse object to host after it has finished executing
    11. Host returns the HttpServletResponse object to the engine
    12. Engine returns the HttpServletResponse object to connector
    13. Connector return the HttpServletResponse object to the customer browser

Transferred from: http://blog.sina.com.cn/s/blog_7cc931cb01014r6n.html

How Tomcat works

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.