This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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: 64629
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: 64629
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