Name

Servlet

Synopsis

The Servlet interface defines the basic structure of a servlet. All servlets implement this interface, either directly or by subclassing a class that does. The interface declares the basic servlet functionality--initializing a servlet, handling client requests, and destroying a servlet.

init() is called when the servlet is first initialized. Since init() is intended to create resources that the servlet can reuse, it is guaranteed to finish executing before the servlet handles any client requests. The server calls the service() method for each client request. The servlet interacts with the client via ServletRequest and ServletResponse objects passed to service(). destroy() is called to clean up resources (such as database connections) or save state when the server shuts down. The getServletInfo() method should return a String that describes a servlet, and the getServletConfig() method should return the ServletConfig object that was passed to the init() method.

public interface Servlet {
// Public Instance Methods
   public abstract void destroy();  
   public abstract ServletConfig getServletConfig();  
   public abstract String getServletInfo();  
   public abstract void init(
        ServletConfig config) throws ServletException;  
   public abstract void service(ServletRequest req, 
        ServletResponse res) throws ServletExceptionIOException;  
}

Implementations

GenericServlet, javax.servlet.jsp.JspPage

Passed To

UnavailableException.UnavailableException(), javax.servlet.jsp.JspFactory.getPageContext() ...

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.