Servlet
A servlet (server Applet) is the abbreviation for a Java servlet, called a small service or service connector, which is a server-side program written in Java that is designed to interactively browse and modify data to generate dynamic Web content.
servlet container
- servlet container startup process:
In the Tomcat container management hierarchy, the context directly manages the wrapper class wrapper of the servlet in the container, so how the Servelt container works affects the servlet, which is the servlet container initiation process
When the servlet container starts, the Servletcontextevent event is triggered and the corresponding listener Servletcontextlistener is notified;
The servlet container monitors the state of ServletContext (initializing or destroying ServletContext) through Servletcontextlistener during startup;
Servletcontextlistener through the Contextinitialized initialization method, The ServletContext is configured according to Web. XML, and the properties of the context container are cached in memory for use by service services;
- Web App initialization work:
The initialization of the Web is implemented in Contextconfig, where the initialization of the application is primarily to parse the Web. XML, which describes the key information of the application and the portal of the entire Web application.
When Tomcat parses the Web. xml file, it sets its properties into the context container, which includes creating servlet instances, filter, and listener. Wraps the servlet into a wrapper class wrapper in the context.
Servlet instances
- Create a Servlet object
If the servlet load-on-startup configuration in Web. XML is greater than 0, it will be instantiated when the context container is started.
- Initialize Servlet
By invoking the servlet's Init method, the Standarwrapperfacade that wraps the Standarwrapper object is passed as ServletConfig to the servlet.
The servlet is parsed from Web. Xml to initialize. The difference between ServletConfig and ServletContext ServletConfig: After a servlet is instantiated, it is valid for any client access at any time, but only for this servlet. A servlet's ServletConfig object cannot be accessed by another servlet.
How the servlet architecture servlet works Listenerfilter in a servlet how to work with Url-pattern in a servlet
Java Web in-depth analysis (8) servlet Working principle analysis