| Author |
Why Not Overload Service Method.
|
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
I am not able to understand why should not we overload service method directly.Why we overload doGet or doPost methods. I know we should implement doGet or doPost methods because service method call doGet or doPost. I want to know what is "advantage of implement doGet or doPost methods then overloading service method." If it is recommanded that we should always implement doGet or doPost then "why service method is implemented in HttpServlet class." Thanks
|
 |
Senthil Kumar
Ranch Hand
Joined: Mar 13, 2006
Posts: 264
|
|
|
I think this has been answered already.There are chances that you want to handle/service the requests based on the request method.
|
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
|
 |
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
|
i am not able to understand can you please explain.
|
 |
Vikrant Pandit
Ranch Hand
Joined: Mar 27, 2006
Posts: 245
|
|
Hmmm ... Http defines many methods ...like GET , POST , PUT ,TRACE ,HEAD etc..... service method in HttpServlet forwards the request to one these methods based on the method specified in incoming request. So in case if you want to your servlet to support get and post but not other methods , then you can only implement doGet and doPost and leave out the other methods . A client trying to do a put request on your servlet gets a status code of 400 meaning operation not supported ... HTH
|
Vikrant Pandit
|
 |
Senthil Kumar
Ranch Hand
Joined: Mar 13, 2006
Posts: 264
|
|
There might be scenarios like you want to respond the GET request in a specific way and the POST request in a way.GET requests are generally meant for just fetching the data and giving it back.And POST request is for updating some thing in the backend.That's why it is called idempotenet. But if you had overriden the serice method instead,you will have only one way of responding. Hope this helps
|
 |
 |
|
|
subject: Why Not Overload Service Method.
|
|
|