wood burning stoves 2.0*
The moose likes Servlets and the fly likes overridding service() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "overridding service() " Watch "overridding service() " New topic
Author

overridding service()

lamaruti reddy
Greenhorn

Joined: Apr 19, 2006
Posts: 7
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

Depends if you want to handle post and gets separately or not.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
lamaruti reddy
Greenhorn

Joined: Apr 19, 2006
Posts: 7
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Jul 16, 2005
Posts: 11
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: overridding service()
 
Similar Threads
Service method
overriding service method
service() method
Unable to direct to page after login
doubt in http methods