Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please reply urgently!!!

 
asheet anand
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic