It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "please reply urgently!!!" Watch "please reply urgently!!!" New topic

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!!!
Frank Carver

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 ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: please reply urgently!!!
jQuery in Action, 3rd edition