This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overridding service()

 
lamaruti reddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally we either override doGet()and/or doPost() but not service method...Can I have the reason?

Is it good practise to override service() method
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends if you want to handle post and gets separately or not.
 
lamaruti reddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my understanding.....

if i need to have different functionality for get and post then....
doget(){//impl1}
dopost(){//impl2}

if i need to have same functionality for get and post then....
doget(){//impl}
dopost(){call doget()}

But my questions is ...do we override even service(httpreq, httpres)method...if so is it good practise...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people will override service, others will code one in terms of the other. I tend to do the latter so that the base class' service() method can deal with the HTTP methods other than post and get.
[ April 19, 2006: Message edited by: Bear Bibeault ]
 
tapan hoskeri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The service() method is usually overriden when you are using a 'GenericServlet'.

If you are using an 'HttpServlet', then the service method handles the delegation of the HTTP request received to one of the appropriate doXXX methods which are defined in the HttpServlet implementation. The Java API Docs mention this in detail, suggest you look them up here...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic