Can we have 3 methods in a single servlet i.e service(), doPost() and doGet() method. If yes, then what method will be called. Tell me the servlet cycle in such cases

Showing Answers 1 - 6 of 6 Answers

charan

  • Oct 20th, 2005
 

first of all service() method will call

then depends upon the request get() or post() method will call

  Was this answer useful?  Yes

kishore

  • Oct 20th, 2005
 

services method will call first......

  Was this answer useful?  Yes

Rajesh Sakhamuri

  • Nov 2nd, 2005
 

First looks for service() method.if service method is not present then servlet looks for the doPost() method.if doPost() method is also not present means then the servlet looks for the doGet() method.But doGet() methods displays the 

  Was this answer useful?  Yes

Rajesh Sakhamuri

  • Nov 2nd, 2005
 

First servlet looks for the service() method.If in the case service() method is not present in that appilication, then looks for the doPost() method.If doPost() method is also not present in your appilication ,then servlet looks for the doGet() method.when u used tha doGet() method,This method will shows to "Querystring" also.It doesnot provide the security.

  Was this answer useful?  Yes

U can have all the 3 methods in a servlet, but only the service() method gets called.

Servlet Container always calls the Service(ServletRequest, ServletResponse) method whenever a new request has come. If ur servlet extends HttpServlet then the Service(ServletRequest, ServletResponse) calls Service(HttpServletRequest, HttpServletResponse) after typecasting the ServletRequest/Reponse to HttpServletRequest/Response. If u override this Service(HttpServletRequest, HttpServletResponse) method then that will be called. If u dont override the service(Ht..,Ht..) then the default implementation of HttpServlet gets called , which in turn calls the doGet() or doPost() based on the <form> tag method.

  Was this answer useful?  Yes

sireesh

  • Mar 24th, 2006
 

If we want to handle all the request types from a single method then the servlet can simply implement the service() method.However if we choose to implement the sevice() method we cannot use the doGet() or doPost methods unless we call super.service at the beginning of the service method.

  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