File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sequence of service

 
JPraveen Kumar
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic