servlet-hierarchy

Ways to create servlet-

1- implement servlet interface-
Servlet interface has total 5 methods
-3 are life cycle methods
(i)init()
(ii)service()
(iii)destroy()

2 are non- life cycle methods-
(i)getServletConfig
(ii)getServletInfo

2- extend GenericSevlet abstract class-

i– it’s a abstract class,
it implements servlet interface,
it has abstract service method

ii– it’s protocol independent.

iii– it belongs to javax.servlet package.

3- extend HttpServlet abstract class-

i– extends genericSerrvlet class and provides implementation of service methods

ii– No abstract methods,
but assigned as abstract so user can’t create object and should be created by server.

iii– it belongs to javax.servlet.http package

Best way to create servlets-> 3- extend HttpServlet abstract class-

Advertisements