Forums Register Login

Why 2 service() methods in HttpServlet??

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
If you read the full description of the methods, the added method includes:

This method is an HTTP-specific version of the Servlet.service...
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3124 times.
Similar Threads
Default implementation of service method in HttpServletClass
service() method in GenericServlet & HttpServlet
service ( ) method overriding or overloading?
service method in HttpServlet
protected Method service???
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:54:05.