The process of starting and processing requests for the Java Web container
1. When starting a Web project, the Web container goes back to read its config file, XML, and reads <Context-param> nodes.
2. The container creates a ServletContext (servlet context), and all parts of the Web project will share this context.
3. The container converts <context-param> into a key-value pair and ServletContext. Because components such as listener,filter use information about these contexts when they are initialized, they are loaded first.
4. Create a <listener> class instance of the container and create the listener.
5. Loading the filter and servlet
The Load-on-startup element specifies the order in which the servlet is loaded when the-web application is started, and its value must be an integer. If its value is a negative integer or the element does not exist, the container will load the servlet when the servlet is called. If the value is a positive integer or 0, the container loads and initializes the servlet when it is configured. The container must ensure that the values are loaded first, and if the values are equal, the container can automatically choose who to load.
The load order for Web. XML is: Context--param--listener--filter--servlet
The process by which a container handles requests
When the Web container receives the request information from the client, it finds the corresponding Servlet object in the servlet queue based on the Web Component address information in the URL, and if found it is used directly, loads the corresponding class if it is not found, and creates the object. In other words, the Servlet object was created the first time it was used, and once created it is reused and no new objects are created. All created servlet objects are garbage collected uniformly when the Web server stops running.
Java Web container Start-up process