Servlet API

Here we can understand the Servlet API as follows:
  • Servlet: javax.servlet.Servlet is an interface which is root for all the servlets we are declaring.
  • Generic Servlet: Generic Servlet is a class which is direct sub class of Servlet Interface.
  1. Generic Servlet is overriding all the methods of Sevlet interface except service() method because of only that Generic Servlet is declare as abstract.
  2. When we develop the servlet by extending Generic Servlet then you have to override service() method as follows: 
            void service(ServletRequest req, ServletResponse res); 

  • HttpServlet : HttpServlet is a class that is direct subclass of Generic Servlet.         
  1. HttpServlet is overriding all the methods of Generic Servlet but HttpServlet is declare as abstract
  2. When we are developing a Servlet by extending HttpServlet then we can override any one the following methods:
void service(HttpServletRequest req, HttpServletResponse res)---Http service
void doGet(HttpServletRequest req, HttpServletResponse res)

void doPost(HttpServletRequest req, HttpServletResponse res)

void doput(HttpServletRequest req, HttpServletResponse res)
void doDelete(HttpServletRequest req, HttpServletResponse res)

void doHead(HttpServletRequest req, HttpServletResponse res)

void doTrace(HttpServletRequest req, HttpServletResponse res)

void doOptions(HttpServletRequest req, HttpServletResponse res)

Note:   Whatever the servlet class you are extending or whatever the methods you are overriding, container always calls the service method.


Post a Comment