Servlets are controlled by the Container
In chapter two we looked at the Container’s overall role in a servlet’s life—it creates the request and response objects, creates or allocates a new thread for the servlet, and calls the servlet’s service() method, passing the request and response references as arguments. Here’s a quick review...

User clicks a link that has a URL to a servlet.

The Container “sees” that the request is for a servlet, so the container creates two objects:
1) HttpServletResponse
2) HttpServletRequest

The Container finds the correct servlet based on the URL in the request, creates or allocates a thread for that request, and calls the servlet’s service() method, passing the request and response objects as arguments.

The service() method figures out which servlet method to call based on the HTTP Method (GET, POST, etc.) sent by the client.
The client sent an HTTP GET request, so the service() method calls the servlet’s doGet() method, passing the request and response objects as arguments.
The servlet uses the response object to write out the response to the client. The response ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access