Name

HttpServlet

Synopsis

The abstract HttpServlet class serves as a framework for servlets that generate content for the World Wide Web using the HTTP protocol. Rather than overriding the service() method, you should override one or more of the method-specific request handlers (doGet(), doPost(), doPut(), etc.). The default service() implementation dispatches incoming requests to the appropriate methods, and so should not be overridden. The default implementations of doGet(), doPost(), doDelete(), and doPut() all return an HTTP BAD_REQUEST error, so if you want to handle one of these kinds of requests, you must override the appropriate method.

A web server calls getLastModified() in response to conditional GET requests. The default implementation returns -1. If you know when the output of your servlet last changed, you can return that time, specified in milliseconds since midnight, January 1, 1970 GMT, instead. This allows web browsers to cache your servlet’s response.

                  Returned By
public abstract class HttpServlet extends GenericServlet implements Serializable {
// Public Constructors
   public HttpServlet();  
// Public Methods Overriding GenericServlet
   public void service(ServletRequest req, 
        ServletResponse res) throws ServletExceptionIOException;  
// Protected Instance Methods
   protected void doDelete(HttpServletRequest req, 
        HttpServletResponse resp) throws ServletExceptionIOException; protected 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.