GenericServlet Class | |
public abstract class GenericServlet extends Object implements Servlet, ServletConfig, Serializable | |
Object GenericServletInterfaces Servlet, ServletConfig, Serializable The GenericServlet class defines a generic, protocol-independent servlet. It provides implementations of the methods declared in the Servlet and ServletConfig interfaces. Because GenericServlet is an abstract class, a GenericServlet object is never created. To create a generic servlet, a class must be written that extends the GenericServlet class and overrides the service() method. |
GenericServlet() | |
public GenericServlet() | Constructor |
This constructor does nothing. The init() methods are used for servlet initialization. |
destroy() | |
public void destroy() | Method |
destroy() unloads the servlet from the server's memory and releases any resources associated with the servlet. |
getServletConfig() | |
public ServletConfig getServletConfig() | Method |
getServletConfig() returns the ServletConfig object associated with the invoking GenericServlet sub-class object. A ServletConfig object contains parameters that are used to initialize the servlet. |
getServletContext() | |
public ServletContext getServletContext() | Method |
getServletContext() returns the ServletContext object associated with the invoking GenericServlet sub-class object. A ServletContext object contains information about the environment in which the servlet is running. |
init() | |
public void init() throws ServletException public void init(ServletConfig config) throws ServletException |
Method |
init() is called when the servlet is loaded into the address space of the server. If a ServletConfig object is specified, it can be used to provide the servlet with initialization parameters. The no-argument version is provided as a convenience method and is intended to be overridden by sub-classes. |
log() | |
public void log(String message) public void log(String message, Throwable thr) |
Method |
log() is used to write a message to the servlet's log file. The second version writes an explanatory message and a stack trace for the specified Throwable exception to the log file. |
getInitParameter() | |
public String getInitParameter(String name) | Method |
getInitParameter() returns the value of the specified initialization parameter from the ServletConfig object associated with the invoking GenericServlet object. |
getInitParameterNames() | |
public Enumeration getInitParameterNames() | Method |
getInitParameterNames() returns an Enumeration of String objects containing the names of all of the servlet's initialization parameters. |
getServletInfo() | |
public String getServletInfo() | Method |
getServletInfo() returns a String containing useful information about the servlet. By default, this method returns an empty String. It can be overridden to provide more useful information. |
getServletName() | |
public String getServletName() | Method |
getServletName() returns the name of the invoking GenericServlet object. |
service() | |
public abstract void service(ServletRequest request, ServletResponse response) throws ServletException, IOException | Method |
service() is called to respond to a request from a client machine. The code representing what the servlet is supposed to do is placed in this method. Because this method is declared abstract, a concrete implementation must be provided by a concrete (non-abstract) sub-class of GenericServlet. |