• Post Reply Bookmark Topic Watch Topic
  • New Topic

Re:Servlet Serivce method  RSS feed

 
rahul kris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Servlets service() is overridden ir no
when it is possible to override
Explain with example+coding
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our first response to questions of this nature is usually: have you tried?

Seriously, it isn't difficult to give it a go.

... and welcome to the Ranch!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to answer this (besides trying it yourself) is to have a look at the API

From java.servlet.Servlet (interface)
service(...): Called by the servlet container to allow the servlet to respond to a request.


From javax.servlet.http.HttpServlet (abstract class)
service(...): Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the Servlet.service(...) method. There's no need to override this method.


What this means is that the service method id designed to be overriden, or at least implemented, and that the default HTTP implementation of the method calls the correct doXXX method. Therefore overriding the doGet and doPost methods is enough, but there is no reason why you cannot still override the service method if it does not provide the behaviour you want.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!