Servlet Container

Servlet Container

  • Servlet container is a sub component of web server that helps both web server and servlet to communicate with each other.
  • As the name implies all servlet of dynamic web application is directly under control of the servlet container.

How servlet container work:

  • Whenever request comes, web server hand over the complete request to servlet container.
  • Container by looking at the URL present in the request and referring web.xml  it comes to know about the servlet which handle the request.


  • After identifying Servlet it creates the instance of servlet.
  • Once instance is successfully created then it convert the row HTTP request to a java object of type “Httpservletrequest ” and create “Htppservletresponse” object.
  • Depending on the HTTP method present in the request container invokes corresponding doXX() method by passing this request and response object.
  • Once doXXX() method execution over, Container convert response object to row HTTP response and gives it back to web server.


  • Once the response has been given back, Servlet container garbage collects the request and response object.
  • In other words for every request container creates new request and response object. i.e. life span of these object is they get created once request come to servlet and they garbage collected once response is given back.

Advantage of Servlet container

Communication support

  • Container help both web server and servlet to communicate with each other.

Multi threading support

  • Container automatically creates new thread for every incoming request.

Declarative support

  • Web.xml which is use by servlet container, we can change behavior of web application without changing anything in the source code.

Life cycle management

  • Container creates and manage the life cycle of servlet.

JSP support

  • Container takes care of converting JSP into a servlet.

Leave a Reply

Your email address will not be published. Required fields are marked *