Can we override the service method?if we can do that then why do we override only doGET()and doPost() methods if the servlet is of protocol specific?

Questions by anandkolam   answers by anandkolam

Showing Answers 1 - 10 of 10 Answers

ak40732

  • Mar 24th, 2006
 

Yes the servlets service method can be overloaded.The Genericservlet service method can be overloaded to support any type of protocol such as Http,Ftp etc.

Theres are specilized servlet for handling HttpProtocol, we call it HttpServlet.The HttpServlet also provides default implementation for service and doGet and doPost methods.The order in which these methods are called is service(ServletRequest,ServletResponse)-calls-->service(HttpServletRequest req,HttpServletResponse res)--calls--either--doGet(HttpServletRequest req,HttpServletResponse res)/doPost(HttpServletRequest req,HttpServletResponse res),so one of these metods need to be override,do get the programmer specific funtionaliy.

  Was this answer useful?  Yes

vijaya

  • Apr 2nd, 2006
 

in http servlet class,the abstart service method of generic servlet class implemented along with two more concrete methods i.e;doGet and do Post

when we define servlet class that extends http servlet then we can override either dopost or doget or both but we are not supposed to override the service method

  Was this answer useful?  Yes

nagan

  • Apr 6th, 2006
 

Service() is overridden by all servlets to get customized functionalities.

doGet() handles the get requests of HTML.

doPost() handles the post requests of HTML.

  Was this answer useful?  Yes

abhijith

  • Oct 30th, 2006
 

Yes, we can override service method.   But then we have to give our own implementation to detect which type of method request is using.(i.e GET or POST).  Since we mostly use HTTP as a protocol itz best to extend HTTPServlet and override doGET or doPOST accordingly.

  Was this answer useful?  Yes

pinkye

  • Jan 11th, 2007
 

You should NOT override the service() method.Your job is to override the doGet() and/or doPost methods and let the service () implementation from HTTPServlet worry about calling the right one.

  Was this answer useful?  Yes

Aqib Ansari

  • May 23rd, 2015
 

we can override service method. but we should not override it. why????

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions