• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between service method and other methods

 
Shilpa Jain
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone pls. explain me why do we use service() method and what is the advantage of using doPost(), doGet() methods?
P.S actually a similar topic was posted earlier but there seems to be some confusion in the explanation
Thanks
 
sandhya Jahagirdar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
when you make a request to the servlet then the service method will be invoked automatically and in that method depending on the header information (get,put,post,etc) that doXXX() method will be invoked. In the books they say that donot try to override the service() method for httpservlet because it handles setup and dispatching to all doXXX methods.for generic servlets you can override service() method
regards
 
S Chandra Mohan
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever u call a servlet
the priority is the service method and then doget and
then dopost.
it is better to write codings in service than the other two
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It makes sense to override service() yourself only if one of the following conditions is met:
1. You are forwarding the request to another class (which may be another servlet or a JSP, for example) which itself needs to decide which method was used.
2. You are really, really sure that you will never need to respond at all to any of the other HTTP requests. Remember that HTTP is not just GET and POST; the service() method as supplied also handles things like HEAD and OPTIONS, and your server may also implement even more request types such as WebDAV.
3. If your code doesn't recognize the request type it calls super.service() to let the server code handle it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic