SERVLET API

 

SERVLET API  

Servlet API Provides packages for servlet processing The two important packages in the servlet API are

                         1. javax.servlet

                         2. javax.servlet.http

 

1. Package javax.servlet

This package consists of number of classes and interfaces . Some of the important interfaces are:

 

Some of the important interfaces are:

                               Servlet                   Defines methods that all servlets must implement.

                               ServletConfig       A servlet configuration object used by a servlet container                                                                              used to pass information to a servlet during initialization.

                               ServletContext     Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.

                               Servlet Request    Defines an object to provide client request information to a servlet.

                             Servlet Response    Defines an object to assist a servlet in sending a response to the client.

                              Single ThreadModel  Ensures that servlets handle only one request at a time.

                           Some of the Import classes are:

                GenericServlet     Defines a generic, protocol-independent servlet.

                    Servlet InputStream  provides an input stream for reading binary data 

from a client request, includeing an efficient readLine method for reading data one line at a time.

                Servlet OutputStream provides an output stram for sending binary data to the client.

               Exceptions

          ServletException    Defines a general exception a servlet can throw when it                                                                 encounters difficulty.

      UnavailableException    Defines an exception that a servlet or filter throws to                                            indicate that  it is permanetly or temporarily unavailable.  

 

2. Package javax.servlet.http  

javax.servlet.http package consists of following important interfaces and classes

 

Some of the important interfaces are:  

     Http ServletRequest   Extends the ServletRequest inteface to provide request information for HTTP serviets.

      HttpServletResponse  Extends the Servlet Response interface to provide                                   HTTP -speccific fuctionallty in sending a response.

      HttpSession     provides a way to identify a user across more than one page request or visit to a website and to store information about that user.

Some important classes are:

Cookie            Creates a cookie, a small amount of information sent by a servlet to a web browser, saved by the browser, and later sent back to the server.

HttpServlet     Provides an abstract class to be subclassed to create an HTTP servlet suitable for a web site. 

             Important Classes and Interfaces

Interface :     Servlet

Package   :    javax.servlet 

Defines  methods that all servlets must implement. 

This interface defines methods to initialize a servlet, to service requests, and to remove a servlet from the server. These are known as life-cycle methods and are called in the following sequence:

1. The servlet is constructed, then initialize with the init method.

2. Any calls from clients to the service method are handled.

3. The servlet is taken out of service, then destroyed with the destroy method , then garbage collected and finalized.

In addition to the life-cycle methods, this interface provides the getServlet Config method, which the servlet can use to get any startup information, and the getServletInfo method, which allows the servlet to return basic information about itself, such as author, version, and copyright.

No comments:

Post a Comment