Top Description Inners Fields Constructors Methods
jakarta.servlet.http

public abstract Class HttpServlet

extends GenericServlet
Class Inheritance
Known Direct Subclasses
org.apache.catalina.manager.JMXProxyServlet, org.apache.catalina.manager.ManagerServlet, org.apache.catalina.manager.StatusManagerServlet, org.apache.catalina.manager.host.HostManagerServlet, org.apache.catalina.servlets.CGIServlet, org.apache.catalina.servlets.DefaultServlet
Imports
java.io.IOException, .OutputStreamWriter, .PrintWriter, .UnsupportedEncodingException, .Writer, java.lang.reflect.InvocationTargetException, .Method, java.text.MessageFormat, java.util.Arrays, .Enumeration, .List, .Locale, .ResourceBundle, jakarta.servlet.AsyncEvent, .AsyncListener, .DispatcherType, .GenericServlet, .ServletConfig, .ServletException, .ServletOutputStream, .ServletRequest, .ServletResponse, .WriteListener

Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:

There's almost no reason to override the service method. service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doMethod methods listed above).

Likewise, there's almost no reason to override the doOptions and doTrace methods.

Servlets typically run on multithreaded servers, so be aware that a servlet must handle concurrent requests and be careful to synchronize access to shared resources. Shared resources include in-memory data such as instance or class variables and external objects such as files, database connections, and network connections. See the Java Tutorial on Multithreaded Programming for more information on handling multiple threads in a Java program.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private volatile String
cachedAllowHeaderValue

Cached value of the HTTP Allow header for this servlet.

private final transient Object
private volatile boolean
cachedUseLegacyDoHead

Cached value read from HttpServlet#LEGACY_DO_HEAD system property.

private static final String
private static final String
public static final String
LEGACY_DO_HEAD

Deprecated for removal since Servlet 6.0. May be removed in a future release
private static final String
private static final ResourceBundle
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final List<String>
private static final long

Constructor Summary

AccessConstructor and Description
public
HttpServlet()

Does nothing, because this is an abstract class.

Method Summary

Modifier and TypeMethod and Description
protected void
doDelete(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
resp
)

Called by the server (via the service method) to allow a servlet to handle a DELETE request.

protected void
doGet(HttpServletRequest
an HttpServletRequest object that contains the request the client has made of the servlet
req
,
HttpServletResponse
an HttpServletResponse object that contains the response the servlet sends to the client
resp
)

Called by the server (via the service method) to allow a servlet to handle a GET request.

protected void
doHead(HttpServletRequest
the request object that is passed to the servlet
req
,
HttpServletResponse
the response object that the servlet uses to return the headers to the client
resp
)

Receives an HTTP HEAD request from the protected service method and handles the request.

protected void
doOptions(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
resp
)

Called by the server (via the service method) to allow a servlet to handle an OPTIONS request.

protected void
doPost(HttpServletRequest
an HttpServletRequest object that contains the request the client has made of the servlet
req
,
HttpServletResponse
an HttpServletResponse object that contains the response the servlet sends to the client
resp
)

Called by the server (via the service method) to allow a servlet to handle a POST request.

protected void
doPut(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
resp
)

Called by the server (via the service method) to allow a servlet to handle a PUT request.

protected void
doTrace(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
resp
)

Called by the server (via the service method) to allow a servlet to handle a TRACE request.

private static Method[]
private String
protected long

Returns:

a long integer specifying the time the HttpServletRequest object was last modified, in milliseconds since midnight, January 1, 1970 GMT, or -1 if the time is not known
getLastModified
(HttpServletRequest
the HttpServletRequest object that is sent to the servlet
req
)

Returns the time the HttpServletRequest object was last modified, in milliseconds since midnight January 1, 1970 GMT.

public void
init(ServletConfig
the ServletConfig object that contains configuration information for this servlet
config
)

Overrides jakarta.servlet.GenericServlet.init.

Implements jakarta.servlet.Servlet.init.

Called by the servlet container to indicate to a servlet that the servlet is being placed into service.

private boolean

Returns:

(@code true} if the HTTP request header is considered sensitive and should be excluded from the response to a TRACE request, otherwise false
isSensitiveHeader
(String
the name of the HTTP request header to test
headerName
)

Is the provided HTTP request header considered sensitive and therefore should be excluded from the response to a TRACE request?

private void
maybeSetLastModified(HttpServletResponse resp, long lastModified)

private void
protected void
service(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
resp
)

Receives standard HTTP requests from the public service method and dispatches them to the doMethod methods defined in this class.

public void
service(ServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
ServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
res
)

Implements abstract jakarta.servlet.GenericServlet.service.

Implements jakarta.servlet.Servlet.service.

Dispatches client requests to the protected service method.

Inherited from jakarta.servlet.GenericServlet:
destroygetInitParametergetInitParameterNamesgetServletConfiggetServletContextgetServletInfogetServletNameinitloglog