This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Sequence of service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Sequence of service" Watch "Sequence of service" New topic
Author

Sequence of service

JPraveen Kumar
Ranch Hand

Joined: Aug 31, 2004
Posts: 80
Hi,

Then at the time of request by client the container calls:
a. Service (HttpServletRequest, HttpServletResponse) of HttpServlet class.
b. doXXX (HttpServletRequest, HttpServletResponse)

If the above is all that happens then when does the Service (ServletRequest, Servletrespponse) of Genericservlet and httpservlet get invoked?

Regards JPraveen
Wim van Haaren
Greenhorn

Joined: Nov 04, 2004
Posts: 18
Hi JPraveen,

The service() method of GenericServlet doesn't get called. But that's the nice thing about polymorphism. The Container calls service() on an object that implements the Servlet interface without knowing its specific class. In most cases this class will be your own Servlet, which extends HttpServlet. So through polymorphism the Container will call the most specific version of service(). However, because you never override service() yourself, the service() method of the superclass HttpServlet gets invoked.

By the way, the doXXX() methods are not called directly by the Container. The container only invokes the service() method. And in HttpServlet it is the service() method which redirects the request to the correct doXXX() method.

Hopefully this makes sense.
Omar Dziri
Greenhorn

Joined: Oct 06, 2004
Posts: 20
There exist two service methods in the HttpServlet:
* protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
Defined to be http dependent,

and the one declared in the Servlet interface (which is protocol independent):
* public void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
throws ServletException, IOException

To process a client request, the web container calls the public service method, it calls in turn the protected service method which calls the appropriate doXXX(...) method.


Master degree in computer systems,<br />SCJP 1.4,<br />SCBCD 1.3,<br />SCWCD 1.4,<br />SCDJWS(in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sequence of service
 
Similar Threads
which service() method is called
basic servlet question
Basic Question about Service Method
How container Handle request
service() method in GenericServlet & HttpServlet