• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Why 2 service() methods in HttpServlet??  RSS feed

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.
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...
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!