What is the servlet

A servlet is essentially just an interface that regulates web requests, enabling classes with some commonality to implement the interface and thus follow the specification (yes, again, a layer of abstraction) to extend Java Web functionality.

Servlet source method:

The Servlet interface specifies five methods:

  • What you do when you initialize
  • Something to do when processing a request
  • Things you do when you destroy them

The servlet itself does not deal directly with the client, but rather through the servlet container

Tomcat with a servlet

Tomcat is a Web application server, which is a Servlet/JSP container. It is the upper layer container that deals directly with the client, and is responsible for distributing the client request to the Servlet, and then transmitting the response of the Servlet to the client.

Spring MVC and servlet

The entry point for all Spring Web applications is a servlet.

The core of Spring MVC framework is DispatcherSeret, which is also a servlet. Spring MVC implements processor adaptation and other function extensions based on Dispatcherseret.

It with the HttpServletResponse

The Web server receives the HTTP request from the client and creates a Request object representing the request and a Response object representing the response for each request.

HttpServletRequest represents the client request. This object encapsulates the request header, request data, and so on.

The HttpServletResponse object represents the server’s response. This object encapsulates methods for sending data, response headers, and response status codes to the client.

reference

What is the nature of servlets and how does it work?

HttpServletResponse Object (1)

SpringMVC from Request to Controller in detail