Servlet is an interface present in javax.servlet package, which has 5 methods declared.
To implement the servlet in our java class we need to implement all the following five methods:
1)public void init(ServletConfig config) : initializes the servlet,in life cycle of servlet this method
is invoked by webcontainer only once.
2)public void service(ServletRequest request,ServletResponse response): it is invoked each time
when the webcontainer requests.
3)public void destroy() : it is invoked once when the servlet is to be destroyed.
4)public ServletConfig getServletConfig(): returns the object of ServletConfig.
5)public String getServletInfo() : returns information about servlet like version,copyright etc.
Basic Servlet
out of the above five methods we generally most of time use service method only.
and rest of the method is usually common for all the servlets.
So to remove this work,we have GenericServlet abstract class in javax.servlet package
which implement all the other methods of servlet interface except service method.
Genric servlet
But this also has some draw backs, as it is Generic so it supports basic features of all protocols but not specific features of any protocols like sessions , cookies etc. features of Http Protocol.
So to overcome this their is HttpServlet abstract class in package javax.servlet.http by extending this class we can all the specific features of Http Protocol.
Http Servlet