• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why 2 service() methods in HttpServlet??

 
Ashutosh Limaye
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServlet is an Abstract class with all the methods that are concrete.

HttpServlet is derived from GenericServlet which is also an abstract class.

HttpServlet has two service() methods one public that is inherited from GenericServlet class that takes (ServletRequest,SetvletResponse)and the other protected service method that overloads the previous method and has
(HttpServletRequest,HttpServletResponse) as parameters.

Now the typical call to the servlet is:

The container calls the public service method ...

the service method internally typecasts the ServletRequest to HttpServletRequest and same with response and calls the protected service
method .
The protected service method then internally verifies if it is GET or POST
and promptly calls doGet() or doPost().

My problem is why doesn't the public service method do the job that the
protected method is doing??...when it already has HttpServletRequest and
HttpServletResponse and also it can call getMethod() method.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read the full description of the methods, the added method includes:

This method is an HTTP-specific version of the Servlet.service...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!