• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Why service() cannot be overridden??  RSS feed

 
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...
 
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!!!
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!