GeeCON Prague 2014*
The moose likes Servlets and the fly likes Why is the Service() method in the servlet not overriden? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Why is the Service() method in the servlet not overriden?" Watch "Why is the Service() method in the servlet not overriden?" New topic
Author

Why is the Service() method in the servlet not overriden?

Akhilesh Murthy
Greenhorn

Joined: Oct 07, 2009
Posts: 24

Why is the Service() method in the servlet not overriden?

Thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
This question doesn't make sense without seeing the piece of code you're talking about. Any particular servlet may or may not override that method (note that's called "service", not "Service"). It's true that almost all servlets do not need to override it, though. I noticed a writeup of this exact question at http://www.coderanch.com/how-to/java/ServletsFaq#overriding-service
Haina Minawa
Ranch Hand

Joined: Oct 13, 2011
Posts: 119
Akhilesh Murthy wrote:Why is the Service() method in the servlet not overriden?

Thanks


I think your question should be changed to "Why should not override servlet's service() method?"


Well, the default implementation of the service() method parses the HTTP method (GET, POST, PUT...) and calls the appropriate methods (doGet(), doPost(), doPut() ...) accordingly. If you override the service() method and do not handle all the HTTP methods correctly, there are chances that some kind of requests would not be served.
 
GeeCON Prague 2014
 
subject: Why is the Service() method in the servlet not overriden?