Processing after tomcat receives http request

The younger brother recently wanted to sort out a whole process of java programming. From the beginning to the end, so, it was born from the beginning. What does a browser do after pressing enter after entering the url?

By searching on the Internet, I found a more reliable one

http://m.blog.csdn.net/zxh476771756/article/details/78716044

Little brother, I quickly wrote it down first, and then digested it slowly. I have no idea about the above-mentioned well-known dns protocol, data link layer, transport layer, and network layer. I have only heard of it in operation and maintenance. It seems that it is necessary to make up for the knowledge of operation and maintenance.

After the above process, the requested packet. Finally arrived at the server, which is the server that restores the data packets to request parameters according to the TCP protocol. Then notify the tomcat that is formulated, so how does tomcat do it?

Suppose the request from the client is:
http://localhost:8080/wsota/wsota_index.jsp

1) The request is sent to the local port 8080, and is obtained by the Coyote HTTP/1.1 Connector listening there
2) The Connector hands the request to the Engine of the Service where it is located for processing, and waits for a response from the Engine
3) The Engine obtains Request localhost/wsota/wsota_index.jsp, matching all virtual hosts it owns Host
4) Engine matches the Host named localhost (even if it does not match, the request is handed over to the Host for processing, because the Host is defined as the Engine The default host)
5) localhost Host gets the request /wsota/wsota_index.jsp, matching all Contexts it has
6) Host matches the Context with the path /wsota (if it does not match, the request is handed over to the path named "" "Context to process)
7) The Context of path="/wsota" obtains the request /wsota_index.jsp, and finds the corresponding servlet in its mapping table
8) The Context matches the servlet whose URL PATTERN is *.jsp, corresponding to JspServlet Class
9) Construct HttpServletRequest object and HttpServletResponse object, call doGet or doPost method of JspServlet as parameters
10) Context returns the HttpServletResponse object after execution to Host
11) Host returns HttpServletResponse object to Engine
12) Engine returns HttpServletResponse object to Connector
13) Connector returns the HttpServletResponse object to the client browser

This is generally the case. But first, we must first understand the core configuration file server.xml of tomcat

First you will see a label:

What does <Server port="8005" shutdown="SHUTDOWN"> mean?

Test:
 telnet localhost 8005   
Input: SHUTDOWN
Result: shutdown tomcat

<server>元素
<Server port="8005" shutdown="SHUTDOWN" debug="0">

1>className specifies the class that implements the org.apache.catalina.Server interface. The default value is org.apache.catalina.core.StandardServer
2>port specifies the port where Tomcat listens to the shutdown command. When the server is terminated, it must be on the machine where the Tomcat server is located Issue the shutdown command on the Tomcat server. This property is required.
3>shutdown specifies the string that is sent to the shutdown listening port of the Tomcat server when the Tomcat server is terminated. This property must be set 

<Service> element
This element is defined by the org.apache.catalina.Service interface, which contains an <Engine> element, and one or more <Connector>, these Connector elements share the same Engine element

<!-- a "Service" " is a combination of one or more "Connectors" that share a single "Container"
       (so that the application is visible in the container). Typically, this container is an "Engine"
       , but this is not required.
       
       Note: A "Service" is not itself a container, so at this level you cannot define
       subcomponents such as "Valves" or "Loggers".
  -->

<!-- Tomcat's Standalone Service
Service is a collection of Connectors
that share an Engine to process requests received by all Connectors
-->

   <Service name="Catalina">
   <Service name="Apache">
   The first <Service> handles all web client requests received directly by the Tomcat server.
   The second <Service> handles all web clients forwarded by the Apahce server ask.

1>className specifies the class that implements the org.apahce.catalina.Service interface. The default is org.apahce.catalina.core.StandardService
2>name defines the name of the Service

The <Connector> element
is defined by the Connector interface. The <Connector> element represents the actual interaction with the client program. It is responsible for receiving client requests and returning response results to the client. 

<!-- A "Connector" represents the endpoint required for a request to be received and answered. Each
         connector handles requests through an associated "Container".
         
         By default, a non-SSL HTTP/1.1 connector is bound to port 8080. You can also create an          SSL HTTP/1.1 connector
         on port 8443 by following the usage instructions below and uncommenting the second connector entry . Open SSL support requires the following steps (see how to configure SSL in the Tomcat 5 documentation for          more details): * If your JDK is version 1.3 or earlier, download and install JSSE 1.0.2 or later, And            place the JAR file in the "$JAVA_HOME/jre/lib/ext" directory.          * Execute with a "changeit" password value:              %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)              $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (UNIX)            to generate itself certificate private key.          By default, DNS queries are enabled when a web application invokes a request. This will make performance


        





           

         This has some adverse effects, so you can turn off DNS lookups by setting "enableLookups" to "false"
         . When DNS lookups are turned off, request.getRemoteHost() will return a string containing the remote client's IP
         address .
  -->

<!-- Coyote HTTP/1.1 Connector attribute description
className : The implementation class of this Connector is org.apache.coyote.tomcat4.CoyoteConnector
port : Listening for HTTP1.1 requests from client browsers at port number 8080. If 8080 is changed If it is 80, just enter  http ://localhost/.
  Protocol: Set the Http protocol, the default value is HTTP/1.1
minSpareThreads: The Connector first creates 5 threads to wait for client requests, each request is responsible for one thread
maxSpareThread: set The maximum number of threads set on the listening port. This value also determines the maximum number of client requests that the server can respond to at the same time. The default value is 200
  acceptCount : When the existing thread has reached the maximum number of 75, queue the client request. When the queue is in When the number of requests exceeds 100, the subsequent request returns a Connection refused error
redirectport: When the client request is https, forward the request to port 8443 to
 enableLookups: if set to true, it means that domain name resolution is supported, and the IP address can be resolved to the host name .WEB application calls the request.getRemoteHost method to return the client host name. The default value is true
 connectionTimeout: defines the timeout time for establishing a client connection. If it is -1, it means that the time for establishing a client connection is not limited

example:

<Connector port="8080" maxThread="50" minSpareThreads="25" maxSpareThread="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />

<Connection port="8009" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" />
The first Connector element defines an HTTP Connector that receives HTTP requests through port 8080; The second Connector element defines a JD Connector that receives requests forwarded by other servers through port 8009.

 

< Engine > element
Each Service element can have only one Engine element. Handles client requests received by all <Connector> elements in the same <Service>. Defined by the org.apahce.catalina.Engine interface. 

<!-- one "Engine" represents the entry point (within Catalina) that handles each request. This standard independent engine implementation of Tomcat
         parses the HTTP header information contained in the request and forwards the request to the appropriate host
         or virtual host. -->

 

<!-- Engine is used to process the Http request received by the Connector.
         It will match the request and its own virtual host, and forward the request to the corresponding Host to process the
         default virtual host is localhost
         -->

<Engine name="Catalina" defaultHost="localhost" debug="0">

1>className specifies the class that implements the Engine interface, the default value is StandardEngine
2>defaultHost specifies the default host name for processing customers, which must be defined in the <Host> sub-element in <Engine>
3>name defines the name of the Engine

The <Engine> can contain the following elements <Logger>, <Realm>, <Value>, <Host> and
other attributes are omitted
-->

The < Host > element
is defined by the Host interface. An Engine element can contain multiple <Host> elements. Each <Host> element defines a virtual host. It contains one or more web applications.

 <!-- Define the default virtual host
           Note: XML schema validation will not work with Xerces 2.2.
      -->

 

<!-- virtual host localhost
           appBase : Specify the directory of the virtual host, you can specify an absolute directory, or you can specify a relative directory relative to <CATALINA_HOME>. If there is no item, the default is <CATALINA_HOME>/webapps. It will match the request and The path of its own Context, and forward the request to the corresponding Context to process
              autoDeploy: If this item is set to true, it means that when the Tomcat service is running, it can monitor the files under appBase. If a new web application is added, it will UnpackWARs
              : If this item is set to true, it means to expand the WAR file of the WEB application into an open directory structure before running it. If it is set to false, it will run directly as a WAR file
              alias: specify the host alias, you can specify Multiple aliases
              deployOnStartup: If this item is set to true, it means that all web applications in the appBase directory will be automatically published when the Tomcat server starts. If there is no corresponding <Context> element in server.xml in the web application, Tomcat's default Context will be used

  -->

<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true">

The <Host> element can contain the following sub-elements
<Logger>, <Realm>, <Value>, <Context>

The < Context > element
is defined by the Context interface. It is the most frequently used element. Each <Context> element represents a single web application running on a virtual host. A <Host> can contain multiple <Context> elements. Each web The application has a unique
corresponding Context representing the web application itself. The servlet container creates a
 

<!-- Context, corresponding to a Web App
             path: The path name of the Context is "", so the Context is the default Context of the Host
             docBase: The root directory of the Context is webapps/mycontext/
                reloadable: If this property is set to true, the Tomcat server will monitor the modification of CLASS files in the WEB-INF/classes and Web-INF/lib directories when it is running. If the monitored class files are updated, the server will reload the web application
                useNaming: Specify whether to support JNDI , the default value is true 
                cookies specify whether to support Session through Cookies, the default value is true

-->

The above is the structure of tomcat's server.xml. Although contact is not short time. But if you look closely, you still don't know much. Only know that he is written in java. It's not clear how java is loaded. Will do some research later

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325479774&siteId=291194637