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 Servlets and the fly likes please reply urgently!!! 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 » Java » Servlets
Bookmark "please reply urgently!!!" Watch "please reply urgently!!!" New topic
Author

please reply urgently!!!

asheet anand
Ranch Hand

Joined: Nov 15, 2000
Posts: 83
hi everyone,
could you please explain to me the use of doGet & doPost
methods in httpservlet,i have read that in case of httpservlet
"service" method dispatches request to doGet & doPost
methods It means that if a html form uses "get" method to connect to a servlet or "post" method service method dispatches
request to doget or dopost method.
my ? is that why we use doGet & doPost methods at all in
servlets when service method can do the trick.
i used "service" method in httpservlet and it works perfect
with "get" or "post" methods
please reply!!!
thanks
asheet
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The HTTP protocol supports more requests than just GET and POST, for example HEAD, PUT and OPTIONS. The default service() method handles all these cases correctly, dispatching them to doHead(), doPut() etc. methods. If you override the service() method (because you assume that you will only ever receieve GET or POST requests) your server will respond to all these other requests as if they are a GET or a POST, which is not correct.
A much better idiom if you wish your POST and GET handlers to use the same code is as follows:


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
Don't get me started about those stupid light bulbs.
 
subject: please reply urgently!!!
 
Similar Threads
Basic Question about Service Method
doGet() & doPost()
code written in scriptlet of JSP
Why only doGet() or doPost() & not service
Using get() and post() together