This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.

This article, the original problem: translate for stackoverflow question stackoverflow.com/questions/3…

This article links to a sequel to the previous article: How do Servlets work? Such as how to instantiate, session Shared variables, multithreading | Java Debug notes

Best answer (continued)

HttpServletRequest and HttpServletResponse

After the servlet container is deployed on the server. Listen on the corresponding port (default 8080 in development environment, 80 in production environment)

When a client (such as the user’s browser or using URLConnection code) sends an HTTP request. The Servlet container will unkey a new HttpServletRequest and HttpServletResponse object and pass them through any Filter on the Filter chain, finally to the Servlet object

When passed to a filter, the doFilter() method is called. When the servlet container code calls chain.dofilter (request, response), request and response will continue to the next filter, Or continue to the servlet if there are no more filters left

In the case of passing to serlvet, the service() method is called. By default, this method determines which of each doXxx() method to use, and whether request.getMethod() gets the request type get, post, or whatever. If the corresponding method does not exist, an HTTP 405 is returned.

The HttpServletRequest object provides all information about an HTTP request, such as the URL, Header, Query String, and body. The HttpServletResponse object provides the means to control and send an HTTP response. For example, HttpServletRequest and HttpServletResponse allow you to set header and body (usually HTML generated from JSP files). When an HTTP response is made, HttpServletRequest and HttpServletResponse are recycled.

See HttpSession in the next article