service() method of GenericServlet class :: The GenericServlet class of the javax.servlet package is an abstract class and it has an abstract service() method which is also public with ServletRequest and ServletResponse objects as its parameters.
So the concrete class extending the GenericServlet class must
implement the service(ServletRequest,ServletResponse) method and we can also [I}override[/I] this method in the subclass.
service method of HttpServlet class :: The HttpServlet class of the javax.servlet.http package is also an abstract class having one protected service() method (not abstract) with HttpServletRequest and HttpServletResponse objects as parameter and one public service method() with ServletRequest and ServletResponse objects of type GenericServlet as HttpServlet is a subclass of GenericServlet.
The protected void service(HttpServletRequest,HttpServletResponse) method receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class.
The public void service(ServletRequest,ServletResponse) method dispatches client requests to the protected service method.
We need not have to
override the service() method of the HttpServlet class as service() method handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods).
But a subclass of HttpServlet must override at least one method, usually one of these:
doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and
destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself
---------------------------------------------------------------------------
K. Anutosh
SCJP 1.4