This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Overridding service() method!?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Overridding service() method!??" Watch "Overridding service() method!??" New topic

Overridding service() method!??

Niyas Ahmed Sheikh
Ranch Hand

Joined: Jun 15, 2005
Posts: 129

I read in some book that overridding the service() is not a good idea. But I seen some codings in which service() method has been overridden.
I want to know when it is needed to override the service() method. If we are overridding the service() method, what about doGet() and doPost().?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Assuming you are talking about the service method in an HttpServlet, then the answer is probably in the code where you've seen this happen. Basically all the service method does is delegates to the appropriate doXXX() method depending on the request. Since HTTP changes only very occasionally, it's very unlikely that you will need to alter its behaviour.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I can't even remember why we did it that way now, but in the early pre-Struts, pre-filter days we had an abstract Front Controller-like class that did something like this:

Not quite the same though.
subject: Overridding service() method!??
jQuery in Action, 3rd edition