Friday, October 16, 2009

web container

Web Container


Container is something that extends the functionality of a web server.Web server cannot alone handle the dynamic pages . The container does it.Tomcat is an eg: of a container. While apache is the web server.Servlets are deployed in the Container.

Container provides -
communication support - we dont have to worry about creating sockets, listners, streams
lifecycle management - it controls the life and death of servlets
multithreading support - automatically creats a new thread when a request comes
provides security - it has a deployment descriptor DD which is an XML which helps to manage the security with out changing java source code.
jsp support - translates the jsp to java

When a request for a dynamic page comes, the web server hands over it to the container and then the container does the following:

container creates two objects - HttpServletRequest and HttpServletResponse
finds the correct servlet based on URL, creates/allocates a thread, passes the request and response object to the servlet thread
calls the service() method
based on the request type the service() method calls doGet() or doPost() method
the doXxx() method generates the dynamic pages and put it into the respose object
thread is completed
container converts the response to Http response and sends it to the client
deletes the request and response objects

Followers