How container handles the Servlet request

1. User clicks a link that has a URL of Servlet.

Client Browse Servlet URL
Client Browse Servlet URL

2. Container (Apache Tomcat is one of the example) sees that the request is for servlet , so create two objects :
HttpServletRequest
HttpServletResponse

HttpServletRequest and HttpServletResponse
HttpServletRequest and HttpServletResponse

3. Container finds correct servlet on the basis of URL passed with the help deployment descriptor (web.xml) file. Creates / Allocate thread for that request and pass request and response object to servle thread.

Create Thread for Servlet
Create Thread for Servlet

4. Container calls the servlets service() method, on the type of request, service calls doGet() or doPost() methods.

Service method of servlet
Service method of servlet

5. Lets assume that service calls the doPost() method. doPost() method generates dynamic page and add the page in response object.

Servlet - doPost  - response object
Servlet – doPost – response object

6. Thread completes, container converts the response object into HttpResponse object and destroys the response and request object.

destroy response and request object
destroy response and request object

Posted

in

by

Tags:


Related Posts

Comments

5 responses to “How container handles the Servlet request”

  1. […] 2 : Then the Container instantiates the Servlet class by calling default Constructor. Read this article to know more that how container works for Servlet. Servlet Life […]

  2. Miranda Avatar
    Miranda

    appreciate the work. really helps

  3. Azhar Avatar
    Azhar

    Nice presentation.
    I have few doubts regarding the http requests handled by tomcat.
    say I’m client, I make http request and suddenly close connection when our code is run still. what will happen to the request.How to handle transaction if i have to roll back entire transaction.Have any Idea on how tomcat handles the request, tomcat keeps all in memory.
    If I have a broken request and nobody is listining to it , how the situation is handled.

  4. Sachin Kale Avatar
    Sachin Kale

    Nice Article.

  5. Vijay Rajgor Avatar
    Vijay Rajgor

    Clear explaination THank you

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading