In-depth analysis of Java Technology Insider
-------------Servlet-------------
1. Overview: How Javaweb works with Servlets, how servlet containers work (tomcat as an example), how Web engineering starts in a servlet container, How the servlet container resolves the servlet defined by the Web. XML, and how the user requests how the servlet lifecycle is managed by assigning to the specified Servlet,servlet container.
2.Servlet relationship to the servlet container: Like a gun and a bullet. To understand decoupling, collaborate with each other through standardized interfaces.
3. Take Tomcat as an example of how a servlet container manages a servlet. The context container directly manages the wrapper class wrapper of the servlet in the container, so the context container directly affects how the servlet works.
4.TOMCAT Container model: Container container Outermost, contains Engine,engine contains host,host contains servlet container, servlet container includes multiple context, each context contains multiple wrapper.
5.Web initialization: When you add a Web app, the Standardcontext container is created and the URL and path are set. The most important configuration is contextconfig, which is responsible for parsing the entire Web application configuration and finally adding the context container to the parent container host.
The 6.Tomcat startup logic is based on the observer pattern, where all containers inherit the lifecycle interface, manage the container's entire lifecycle, and notify the Observer (Listener) of all container modifications and state changes.
7. Initialization of Contextconfig: Parsing Web. XML, wrapping the servlet as a standardwrapper in a context container (not wrapped as a servlet object reason: Standardwrapper is part of the Tomcat container, has the characteristics of the container, and Servlets are independent web development standards and should not be strongly coupled in Tomcat.
The 8.Context container is the servlet container that really runs the servlet. A Web application corresponds to a context container, and the configuration properties are specified by the application's Web. Xml.
9.Servlet instance creation (before the parsing of the servlet is completed and wrapped into Standardwrapper added in the context container).
10.Servlet Active Association (implements three interfaces) three classes: Servletconfig,servletrequest,servletresponse. The servletconfig is passed to the servlet when the servlet is initialized, and the latter two are called by the servlet when the request arrives. ServletConfig is to get the configuration properties of the servlet, Standardwrapper and ApplicationContext use the façade mode and implement the ServletConfig interface. ServletConfig implements the necessary information for servlecontext,servletcontext including the working path in the context container. Instead, Servletrequest,servletresponse translates to HttpServletRequest and HttpServletResponse classes in their own servlet classes.
11. The user initiated a request from the browser to the server including: Http:hostname:port/contextpath/servletpath, the first two established TCP connections, followed by the URL selection Server sub-container service user request to reach the servlet container, This mapping is done by the Mapper class (before the Tomcat5) (5 is moved to request), preserving all the child container information in the Tomcat container container, before the request class enters the container container. Mapper has set the host and context containers to the Requst attribute according to hostname and ContextPath, guaranteeing that the request enters the container container before determining the child container to be accessed.
The listener in the 12.TOMCAT based on the Observer pattern is widely used, and all inherit the EventListener interface.
13.Filter provides a Filterchain object in addition to the request and response objects.
-------------Tomcat-------------
1.tomcat Two core components: connector and container. A container can select multiple connector and form a service,service that is included in the server.
2. A service can set up a container container and multiple connector. The Service interface standard implementation class is Standardservice and implements the lifecycle interface.
3.Server interface: Let other programs access service collections and maintain their lifecycle.
4.Lifecycle interface: Control the life cycle.
5.Connector component: Accepts a TCP connection request from the browser, creating requests and reponse objects for exchanging data with the requester side. It then generates a thread-processing request and passes the request and Reponse objects to the thread that handles the request (multithreading is the core of the connector design), and the container component processes the requesting thread.
6.Container components: As described in the servlet, there are four components that are parent-child relationships: Engine,host,context,wrapper, an engine represents the complete servlet engine.
7. A host represents a virtual host in the engine and installs and expands multiple applications (eg. localhost in the URL).
8.Context: Manages servlet instances that appear as wrapper, starting sub-containers and pipeline. With the basic operating environment of the servlet, it is theoretically possible to run the servlet as long as there is contxt.
9.Wrapper: The implementation class is Standardwrapper, implements the ServletConfig that has the initial servlet information, represents a servlet, manages the servlet, including the servlet's loading, initialization, execution, and resource recycling.
Tomcat-based Servlet learning notes