HttpServlet must override at least one method, usually one of these:
doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself
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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private volatile String | cachedAllowHeaderValue
Cached value of the HTTP |
| private final transient Object | |
| private volatile boolean | cachedUseLegacyDoHead
Cached value read from |
| 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 | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | doDelete(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientCalled by the server (via the |
| protected void | doGet(HttpServletRequest
an req, HttpServletResponse HttpServletRequest object that contains the request the client has made of the servletan resp)HttpServletResponse object that contains the response the servlet sends to the clientCalled by the server (via the |
| 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 |
| protected void | doOptions(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientCalled by the server (via the |
| protected void | doPost(HttpServletRequest
an req, HttpServletResponse HttpServletRequest object that contains the request the client has made of the servletan resp)HttpServletResponse object that contains the response the servlet sends to the clientCalled by the server (via the |
| protected void | doPut(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientCalled by the server (via the |
| protected void | doTrace(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientCalled by the server (via the |
| private static Method[] | |
| private String | |
| protected long | Returns: along 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 knownthe req)HttpServletRequest object that is sent to the servletReturns the time the |
| public void | init(ServletConfig
the config)ServletConfig object that contains configuration information for this servletOverrides jakarta. Implements jakarta. 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 aTRACE request, otherwise falsethe 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
|
| private void | |
| private void | |
| protected void | service(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientReceives standard HTTP requests from the public |
| public void | service(ServletRequest
the req, ServletResponse HttpServletRequest object that contains the request the client made of the servletthe res)HttpServletResponse object that contains the response the servlet returns to the clientImplements abstract jakarta. Implements jakarta. Dispatches client requests to the protected |