1. We know that Tomcat can be started by the org. Apache. Catalina. startup. Bootstrap class. This type does two things:
1. Specify classloader
2. Boot Catalina and use reflection technology to call the process () method of org. Apache. Catalina. startup. Catalina and pass the parameter in the past. Public void process (string ARGs [])
The process () of Catalina. Java does the following:
A: Use digester technology to assemble Tomcat containers and components (server. xml file loading );
B: Initialize the top-level server.
C: Start from the container server, ---- go to the next step (2)
D: Create a hook program for the server. When the server is closed, close the entire tomact container.
E: Listen to port 8005. If shutdown is triggered, disable socket on port 8005.
2. Start the container
Server (representing the entire container): triggers the event before, during, and after startup in the server container, and runs the event processor.
Server ----> Start the sub-Container Service of the server (specify the components that provide the service, one or more can be configured in server. XML)
<!-- A "Service" is a collection of one or more "Connectors" that share a single "Container" Note: A "Service" is not itself a "Container", so you may not define subcomponents such as "Valves" at this level. Documentation at /docs/config/service.html -->
Service ----> Start the engine container and start connector (each service has only one engine and can have multiple connector)
The engine specifies the host name that processes client requests received by all ctor.
Connector defines the service port number, which is responsible for receiving customer requests and returning corresponding results to the customer.
Engine ----> host (one or more hosts indicate one virtual host, which can contain one or more web applications)
Host ----> context (each context represents a single web application running on the host .)
Standardcontext. Start () is called by standardhost:
1. Specify loader and use the default org. Apache. Catalina. loader. webapploader. loader is used to specify the classes and jar packages used by the context.
2. Specify the manager. The default org. Apache. Catalina. session. standardmanager is usually used. Manager is used to manage sessions. After obtaining the request, the request has a session attribute.
3. Binding thread. Here, Class Loader swaps should occur. We can see all the classes and Lib under Tomcat before. Next we need to see the classes under the current context. Therefore, you must set contextclassloader and record the old classloader, because it will be used later.
4. Start loader. Specify the classes and jar files used for the context. If reloadable is set to true, a thread is started to monitor classes changes. If there is any change, context is restarted.
5. Start Logger
6,Trigger the listener on the context,As one of the listeners, contextconfig will be started. contextconfig is used to configure web. xml. For example, how many servlets and filters are contained in the context are installed in the context.
6.1 defaultconfig. The tomcat/CONF/Web. xml file must be configured for each context.
6.2 applicationconfig configure your own WEB-INF/Web. xml file
6.3. validatesecurityroles permission verification. When accessing/admin or/manager, users must be either admin or manager. In addition, we can restrict the resources that can be accessed, but which cannot. All are implemented here.
6.4. tldscan: the tags needed for scanning (TAG Lab)
7. Start Manager
8. postwelcomefiles:
Index.html#index.htm and index. jsp are bound to this context by default.
9. listenerstart configures listener and initializes listener.
10. Configure filter in filterstart and initialize filter.
11. Start the servlet with <load-on-startup>; 1 </load-on-startup>.
The order is from small to large: 1, 2, 3... Last 0
By default, at least three servlets are started:
Org. Apache. Catalina. servlets. DefaultServlet
Servlet for processing static resources. What images? HTML? CSS? JS? Look for him?
Org. Apache. Catalina. servlets. invokerservlet
Process the servlets that are not engaged in Servlet Mapping.
Org. Apache. Jasper. servlet. jspservlet
Process.
12. The context has been started.
The key code will be added later ..