A servlet container is a complex system. However, basically there are three things that a servlet container does to service a request for a servlet:
- Creating a requestion instance and populate it with information that may be used by the invoked servlet, such as parameters, headers, cookies, query string, URI, etc. A request object is an instance of javax.servlet.ServletRequest interface or the javex.servlet.http.ServletRequest interface.
- Creating a response object that the invoked servlet uses to send the response to the web client. A response object is an instance of the javax.servlet.ServletResponse interface or the javax.servlet.http.ServletResponse interface.
- Invoking the service method of the servlet, passing the request and response objects. Here the sevlet reads the values from the request object and writes to the response object.
Simplistic Block Diagram
![SimplisticBlockDiagram SimplisticBlockDiagram](http://hi.csdn.net/attachment/201012/3/0_1291388610r2Sw.gif)
The connector is there to connect a request with the container. Its job is to construct a request object and a reponse object for each HTTP request it receives. It then passes processing to the container. The container receives the request and response objects from the connector and is responsible for invoking the servlet's method.
Let's examine servlet programming from a servlet container's perspective. In a nutshell, a fully-functional servlet container does the following for each HTTP request for a servlet:
- When the servlet is called for the first time, load the servlet class and call the servlet's init method (once only).
- For each request, construct an instance of javax.servletServletRequest and and instance of javax.servlet.ServletResponse.
- Invoke the servlet's service method, passing the ServletRequest and ServletResponse object.
- When the servlet class is shut down, call the servlet's destroy methodand unload the servlet class.