What is a servlet?
A servlet is a Java class that is used to extend the capabilities of servers that host server-side web applications. Servlets can respond to requests and generate responses. The base class for all servlets is jakarta.servlet.GenericServlet
. This class defines a generic, protocol-independent servlet.
By far the most common type of servlet is an HTTP servlet. This type of servlet is used when handling HTTP requests and generating HTTP responses. An HTTP servlet is a class that extends the jakarta.servlet.
http.HttpServlet class, which is a subclass of jakarta.servlet.GenericServlet
.
A servlet must implement one or more methods to respond to specific HTTP request types. These methods are overridden from the parent HttpServlet
class. As can be seen in Table 11.1, these methods are named so that knowing which one to use is intuitive.
HTTP Request |
HttpServlet Method |