Docstoc

servlet 2

Document Sample
servlet 2 Powered By Docstoc
					A web server is the combination of computer and the program installed on
it. Web server interacts with the client through a web browser. It
delivers the web pages to the client and to an application by using the
web browser and he HTTP protocols respectively. We can also define the
web server as the package of large number of programs installed on a
computer connected to Internet or intranet for downloading the requested
files using File Transfer Protocol, serving e-mail and building and
publishing web pages. A web server works on a client server model. A
computer connected to the Internet or intranet must have a server
program. While talking about Java language then a web server is a server
that is used to support the web component like the Servlet and JSP. Note
that the web server does not support to EJB (business logic component)
component.

A computer connected to the Internet for providing the services to a
small company or a departmental store may contain the HTTP server (to
access and store the web pages and files), SMTP server (to support mail
services), FTP server ( for files downloading) and NNTP server (for
newsgroup). The computer containing all the above servers is called the
web server. Internet service providers and large companies may have all
the servers like HTTP server, SMTP server, FTP server and many more on
separate machines. In case of Java, a web server can be defined as the
server that only supports to the web component like servlet and jsp.
Notice that it does not support to the business component like EJB.

Servlet container : A servlet container is nothing but a compiled,
executable program. The main function of the container is to load,
initialize and execute servlets. The servlet container is the official
Reference Implementation for the Java Servlet and JavaServer Pages
technologies. The Java Servlet and JavaServer Pages specifications are
developed by Sun under the Java Community Process.

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 ServletRequest object and a ServletResponse object.
    If the request is for a static resource, invoke the process method of
the StaticResourceProcessor instance, passing the ServletRequest and
ServletResponse objects.
    If the request is for a servlet, load the servlet class and invoke
its service method, passing the ServletRequest and ServletResponse
objects. Note that in this servlet container, the servlet class is loaded
every time the servlet is requested.

II. A fully functional servlet container additionally 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 its init method (once only).
    For each request, construct an instance of
javax.servlet.ServletRequest and an instance of
javax.servlet.ServletResponse.
    Invoke the servlet's service method, passing the ServletRequest and
ServletResponse objects.
    When the servlet class is shut down, call the servlet's destroy
method and unload the servlet class.

Now lets see what a servlet container does for each HTTP request for a
servlet, in general :

    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.

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:7/18/2012
language:
pages:2