By implementing the Servlet interface: The
servlet interface provides normal behavior for all servlets. The
servlet interface defines the methods that all servlets should
implement. The servlet interface must be implemented to create
(directly or indirectly) any servlet. It provides 3 life-cycle
methods, which are used for starting a servlet, servicing requests
and destroying a servlet, and 2 non-life-cycle methods.
By inheriting GenericServlet class : The
GenericServlet class implements servlet, servlet config, and
serialized interfaces. It provides the implementation of all
methods of these interfaces, except for the service method. The
GenericServlet class can handle any type of request, so it is
protocol-independent. You can create a universal servlet by
inheriting the GenericServlet class and providing an implementation
of the service method.
By inheriting HttpServlet class: HttpServlet
is an abstract class defined according to the current servlet up.
This is present in javax. Servlet. ... it extends the
GenericServlet class. When a servlet container uses HTTP to send
requests, it creates HttpServletRequest and HttpServletResponse
objects.