2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
A web server that runs Java servlet and JSP technology, can provide a running environment for Java web and process client requests through the HTTP protocol. That is, Tomcat = HTTP server + servlet container. Similar products include Jetty
Connector + container
The container is the engine, host, context, servlet/wrapper
So the architecture is service (port 8080), connector, engine, host (http:localhost.com), context (/mvc, a web application), servlet/wrapper (/add, a servlet)
Used for: Network layer communication TCP/IP, such as NIONIO2
Used for: application layer protocol analysis, such as http
Used for: unified conversion. Convert tomcat request/response to servlet request/response, and then pass it to the container.
3.2.1 Design ideas for changing points and unchanged points
The invariant points are implemented with abstract classes and interfaces (such as ProtocolHanlder and AbstrctProtocol), and the variable points are implemented with specific classes (such as Http11NioProtocol and Http11Nio2Protocol).
3.2.2 Adapter Pattern
Adapter,tomcat用CoyoteAdapter。
To put it simply, a class/interface is used to assemble a tree structure (with a parent-child relationship). This is called combination. Then, because they all implement the same interface, the calls to each part are the same.
Pipeline is a chain of responsibility, a queue, and the elements in the queue are valves. The valve can execute the processing logic and transfer to the next value.
The difference between valve and filter: valve is for Tomcat, filter is for Java Servlet API. Valve works at the web container level, intercepting all application requests, filter works at the application level, intercepting a web application request
Assign request: map the mapper component. Find the corresponding wrapper layer by layer according to the URL.
Lifecycle: responsible for container creation, initialization, startup, destruction, etc. Each Container inherits LifeCycle. So it is also a composite mode.
The observer mode is also used (listening to change the life cycle status),
Combination mode (tree structure with parent-child relationship),
Template design pattern (write a general template (general logic), call new methods in the template, and implement the new methods in detail)