0% found this document useful (0 votes)
43 views

Servlet Session 1.2

The document describes how a servlet handles requests internally. The web container maps requests to servlets, creates request and response objects, and calls service methods like doGet which generate responses. Request and response objects are then deleted and threads returned to a pool.

Uploaded by

JEEVAN SONAWANE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Servlet Session 1.2

The document describes how a servlet handles requests internally. The web container maps requests to servlets, creates request and response objects, and calls service methods like doGet which generate responses. Request and response objects are then deleted and threads returned to a pool.

Uploaded by

JEEVAN SONAWANE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

How Servlet internally works?

The web container is responsible to handle the request. Let's see how it handles the
request.

o maps the request with the servlet in the web.xml file.

o creates request and response objects for this request

o calls the service method.

o The public service method internally calls the protected service method

o The protected service method calls the doGet method depending on the type of
request.
o The doGet method generates the response and it is passed to the client.

o After sending the response, the web container deletes the request and response
objects. The thread is contained in the thread pool or deleted depends on the
server implementation.

1. When User sends request for a servlet by clicking a link that has URL to a
servlets.

2. The container finds the servlet using deployment descriptor and creates two


objects :

a. HttpServletRequest
b. HttpServletResponse
3. Then the container creates or allocates a thread for that request and calls the
Servlet's service() method and passes the request, response objects as
arguments.

4. The service() method, then decides which servlet method, doGet() or doPost() to


call, based on HTTP Request Method(Get, Post etc) sent by the client. Suppose
the client sent an HTTP GET request, so the service() will call
Servlet's doGet() method.
5. Then the Servlet uses response object to write the response back to the client.

6. After the service() method is completed the thread dies. And the request and


response objects are ready for garbage collection.

You might also like