• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why service() cannot be overridden??

 
Sandya Bhaskara
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why can't u override service() in HttpServletClass??HFS says never to override this method.....
but why not override this method so that the servlet will service any request from the client(irrespective of whether the request is get,post,put etc)....i have written code overriding the service method and it executed fine...
 
marco borsato
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
service automatically chooses whether too use doget or dopost or something else. If you override it you have to call the methods yourself. any way you need dopost or doget to handle the requests. If not specified the servlet won't know what to do!!!
 
Sami Sayeed
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandhya,

as marco has indicated,
If you override service then you need to write the logic for calling the doPost and doGet in your servlet,
but because your requirement is regardless of doGet and doPost you want to execute teh same logic which you can achive by
doGet() // assume all the parameters are there
{
call doPost();
}
doPost()
{
your logic
}
by overriding service you cannot differentiate even the head,trace,options requests.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic