Package jakarta.servlet.http
Class HttpServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
- All Implemented Interfaces:
Servlet,ServletConfig,Serializable
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:
doGet, if the servlet supports HTTP GET requestsdoPost, for HTTP POST requestsdoPut, for HTTP PUT requestsdoDelete, for HTTP DELETE requestsinitanddestroy, to manage resources that are held for the life of the servletgetServletInfo, 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 doXXX 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.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidservice(ServletRequest req, ServletResponse res) Dispatches client requests to the protectedservicemethod.Methods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
-
Constructor Details
-
HttpServlet
public HttpServlet()Does nothing, because this is an abstract class.
-
-
Method Details
-
service
Dispatches client requests to the protectedservicemethod. There's no need to override this method.- Specified by:
servicein interfaceServlet- Specified by:
servicein classGenericServlet- Parameters:
req- theHttpServletRequestobject that contains the request the client made of the servletres- theHttpServletResponseobject that contains the response the servlet returns to the client- Throws:
IOException- if an input or output error occurs while the servlet is handling the HTTP requestServletException- if the HTTP request cannot be handled or if either parameter is not an instance of its respectiveHttpServletRequestorHttpServletResponsecounterparts.- See Also:
-