A container handles large number of requests as it can hold many active servlets, listeners etc. It is interesting to note here that the container and the objects in a container are multithreaded. So each object must be thread safe in a container as the multiple requests are being handled by the container due to the entrance of more than one thread to an object at a time.
Note : A Servlet container may run stand alone i.e. without a web server or even on another host.
We can categorize the servlet containers as:
I. A simple servlet container is not fully functional and therefore it can only run very simple servlets and does the following :
- Wait for HTTP request.
- Construct a
ServletRequestobject and aServletResponseobject. - If the request is for a static resource, invoke the
processmethod of theStaticResourceProcessorinstance, passing theServletRequestandServletResponseobjects. - If the request is for a servlet, load the servlet class and invoke its
servicemethod, passing theServletRequestandServletResponseobjects. Note that in this servlet container, the servlet class is loaded every time the servlet is requested.
- When the servlet is called for the first time, load the servlet class and call its
initmethod (once only). - For each request, construct an instance of
javax.servlet.ServletRequestand an instance ofjavax.servlet.ServletResponse. - Invoke the servlet's
servicemethod, passing theServletRequestandServletResponseobjects. - When the servlet class is shut down, call the servlet's
destroymethod and unload the servlet class.
- The servlet container loads the servlet class and calls the init method of the servlet as soon as the servlet is called for the first time.
- Then this container makes an instance of javax.servlet.ServletRequest and javax.servlet.ServletResponse for each request.
- Then it passes the ServletRequest and ServletResponse objects by invoking the servlet's service method.
- Finally, it calls the destroy method and unload the servlet class when the servlet class is to be shut down.
0 comments:
Post a Comment