This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why Not Overload Service Method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why Not Overload Service Method." Watch "Why Not Overload Service Method." New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Not Overload Service Method.
 
Similar Threads
doGet() and doPost()
please reply urgently!!!
Is a Servlet thread-safe
why we should not override service() method in a servlet
when to use these methods....