• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Akhilesh Murthy
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the Service() method in the servlet not overriden?

Thanks
 
Tim Moores
Bartender
Posts: 2749
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic