All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class javax.servlet.GenericServlet

java.lang.Object
   |
   +----javax.servlet.GenericServlet

public abstract class GenericServlet
extends Object
implements Servlet, ServletConfig, Serializable
Abstract base class for all servlets.

Version:
Servlet API 2.0

Constructor Index

 o GenericServlet()
Does nothing.

Method Index

 o destroy()
Called by the server when it no longer needs the servlet.
 o getInitParameter(String)
Gets a servlet's initialization parameter
 o getInitParameterNames()
Gets all the initialization parameters
 o getServletConfig()
Gets the servlet config class
 o getServletContext()
Returns the servlets context
 o getServletInfo()
The servlet programmer can put other additional info (version number, etc) here.
 o init(ServletConfig)
Initializes the servlet.
 o log(String)
Writes the class name and a message to the log.
 o service(ServletRequest, ServletResponse)
Called by the server every time it wants the servlet to handle a request.

Constructors

 o GenericServlet
 public GenericServlet()
Does nothing.

Methods

 o init
 public void init(ServletConfig config) throws ServletException
Initializes the servlet. Called by the server exactly once during the lifetime of the servlet. This method can be used to setup resources (connections to a database for example) for this servlet. Note that if a servlet overrides this method it should call super.init(config) otherwise the other methods in GenericServlet are not garanteed to work.

Parameters:
config - This servlet configuration class
Throws: ServletException
If an error occurs
 o getServletContext
 public ServletContext getServletContext()
Returns the servlets context

Returns:
The context
 o getInitParameter
 public String getInitParameter(String name)
Gets a servlet's initialization parameter

Parameters:
name - the name of the wanted parameter
Returns:
the value of the wanted parameter. null if the named parameter is not present.
 o getInitParameterNames
 public Enumeration getInitParameterNames()
Gets all the initialization parameters

Returns:
an Enumeration of all the parameters
 o log
 public void log(String message)
Writes the class name and a message to the log. Calls getServletContext().log().

Parameters:
message - the message to write
 o getServletInfo
 public String getServletInfo()
The servlet programmer can put other additional info (version number, etc) here.

The Servlet 2.1 Spec says that this should return an empty string. The Servlet 2.1 API says that this should return null unless overridden. This version returns the servlet's class name which seems more usefull.

Returns:
The String holding the information
 o getServletConfig
 public ServletConfig getServletConfig()
Gets the servlet config class

Returns:
The config class
 o service
 public abstract void service(ServletRequest request,
                              ServletResponse response) throws ServletException, IOException
Called by the server every time it wants the servlet to handle a request.

Parameters:
request - all the request information
response - class to write all the response data to
Throws: ServletException
If an error occurs
Throws: IOException
If an error occurs
 o destroy
 public void destroy()
Called by the server when it no longer needs the servlet. The servlet programmer should use this method to free all the resources the servlet is holding.

This version does nothing because it has nothing to clean up.

Note that the the 2.1 Spec says that this should do nothing, but the 2.1 API Doc says that it logs the destroy action.


All Packages  Class Hierarchy  This Package  Previous  Next  Index