• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

difference between service method and other methods

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic