Step 3: Servlet creation


Ways to create Servlet-

1- implement Servlet interface-
Servlet interface has total 5 methods
-3 are life cycle methods

2 are non- life cycle methods-

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-