Name

GenericServlet

Synopsis

The GenericServlet class provides a basic implementation of the Servlet and ServletConfig interfaces. If you are creating a protocol-independent servlet, you probably want to subclass this class rather than implement the Servlet interface directly. Note that the service() method is declared as abstract; this is the only method you have to override to implement a generic servlet.

GenericServlet includes basic implementations of the init() and destroy() methods, which perform basic setup and cleanup tasks, respectively. The init() method that takes a ServletConfig object stores that object for later use. This means that if you override the method and fail to call the super.init(ServletConfig) method, you won’t be able to use the ServletConfig methods later. In version 2.1 of the Servlet API, you can override a no-argument version of init() that is dispatched by the default init(ServletConfig) method of GenericServlet.

                  Passed To
public abstract class GenericServlet implements Servlet, ServletConfig, Serializable {
// Public Constructors
   public GenericServlet();  
// Public Instance Methods
   public void init() throws ServletException;                   // empty, 2.1
   public void log( String msg);  
   public void log( String message, Throwable t);                // 2.1
                  // Methods Implementing Servlet
   public void destroy();  
   public ServletConfig getServletConfig();  
   public String getServletInfo(); public void  ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.