notes

Servlet class ← GenericServlet class ← HttpServlet class ← MyServlet class (self-built class) (← stands for inheritance).

So when we create the Servlet class, we just need to inherit the HttpServlet class and rewrite the doGet() and doPost() requests that we need, which correspond to the client get and POST requests.

The original

Link: www.nowcoder.com/questionTer… Source: Niuke.com

Servlet class ← GenericServlet class ← HttpServlet class ← MyServlet class (self-built class) (← stands for inheritance).
The Servlet class contains the three necessary lifecycle methods required: Init () initializes the Servlet, service() requests the corresponding Servlet, and destroy() destroys the Servlet, but direct inheritance requires overriding all methods, so GenericServlet class inherits the Servlet class and implements all methods, but it is not an HTTP protocol class. GenericServlet is an HTTP protocol class inherited from the HttpServlet class.
So when we create the Servlet class, we just need to inherit the HttpServlet class and rewrite the doGet() and doPost() requests that we need, which correspond to the client get and POST requests.