I agree All servlets extend HttpServlet and it has a method service()
but which service() method Is this right that
The container calls the service(ServletRequest,ServletResponse) method of HttpServlet.
The service(ServletRequest,ServletResponse) method of HttpServlet calls then service(HttpServletRequest,HttpServletResponse) method of the same class,as the service() method is overloaded in HttpServlet class.
or container directly call the service(HttpServletRequest,HttpServletResponse) method
Thanks & Regards
Gaurav
Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
Bosun (SCJP, SCWCD).
So much trouble in the world -- Bob Marley
Originally posted by Bosun Bello:
The conatainer calls the first service method, which in turn calls the http service method to handle to http requests.
Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
I guess rules apply similar to overloaded methods. If your reference object is HttpServlet then service(HttpServletRequest,HttpServletResponse) method is called.
SCJP 5 - SCWCD 1.4 - SCBCD 1.3 - Certification study documents/resources: http://esnault.frederic.free.fr/certification
protected void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException
Chandra Sagi wrote:Hi Frederic,
I did not know that accesss modifier for service method in HttpServlet is protected.
I looked in the API and found it to be
protected void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException
The order of execution when a servlet gets called is:
init(ServletConfig sc)
init()
service(ServletRequest, ServletResponse)
service(HttpServletRequest, HttpServletResponse)
Correct me if I am wrong.
Thanks for your help.
Chandu
Hitesh Pawar wrote:
Chandra Sagi wrote:Hi Frederic,
I did not know that accesss modifier for service method in HttpServlet is protected.
I looked in the API and found it to be
protected void service(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException
The order of execution when a servlet gets called is:
init(ServletConfig sc)
init()
service(ServletRequest, ServletResponse)
service(HttpServletRequest, HttpServletResponse)
Correct me if I am wrong.
Thanks for your help.
Chandu
Hi Chandu,
The order in which servlet container calls service method is as follows:
1) Container first calls service(ServletRequest req, ServletResponse response) upon the servlet called. If this method not overrided then superclass(HttpServlet) default version will be called.
2) The default version then calls service(HttpServletRequest req , HttpServletResponse res) overloaded method which you have overriden in your servlet.
Further if you override service(ServletRequest req, ServletResponse response) then you won't get default implementation(i.e. calling service(HttpServletRequest req , HttpServletResponse res) ).