aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes service() in HttpServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "service() in HttpServlet" Watch "service() in HttpServlet" New topic
Author

service() in HttpServlet

Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
I have some doubt in ServletModel.
How the Servlet get instantiated ? we all know that it first call init() method, then service method() & destroy().
How the service() is mapped to corresponding GET or POST.
so for HttpServlet is this flow ???

init()
doGet()/doPost()
destroy()

or
init()
service()
doGet()/doPost()
destroy()

Thanks & Regards
Mike
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
The latter, really. The container implements the service method so that it calls the appropriate doXXX method. The service method should never be overriden.
Hisham Marie
Greenhorn

Joined: Jun 13, 2002
Posts: 7
I would add that the servlet service method calls the getMethod() from the request object to specify which doXXX method it has to call.
Regards
Hisham
Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
But which service() method it calls.
service(ServletRequest req,ServletResponse res)
or
service(HttpServletRequest req,HttpServletResponse res)
Thanks & Regards
Mike
Andreas Christoforides
Greenhorn

Joined: Jun 28, 2002
Posts: 4
Upon receiving a request, the servlet container/engine first calls the
service(ServletRequest req,ServletResponse res) method of the servlet.
Then the
service(ServletRequest req,ServletResponse res) method will call the
service (HttpServletRequestreq,HttpServletResponse res) method.
The service (HttpServletRequestreq,HttpServletResponse res) method will then analyze the request and call the appropriate doXXX() method.
This is the flow of control from the servlet container/engine to the doXXX() methods as defined in the HttpServlet javadoc and the SCWCD Exam Kit book.
Hope that was helpfull,
Andreas


=========================<br />SCJP2 (Passed with 89%)<br />SCJP2 (Passed with 93%)<br />Preparing for SCBCD<br />=========================
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

If you are using the service method then it is instead of doGet and doPost. You can not use both service and doGet/doPost.
/Rene


Regards, Rene Larsen
Dropbox Invite
Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
Hoo cool...
Thanks & Regards
Mike
Doug Kearns
Greenhorn

Joined: Jul 01, 2002
Posts: 2
When you are in doubt about things like this why not have a look at the Tomcat source code?
Regards,
Doug
Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
Hi Doug,
I didnt get ur question, see tomcat source code ?
Thanks & Regards
Mike
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"Tomcat" is the reference implementation of the Servlet and JSP APIs. If you are unsure of the meaning of the specification in any area, then you can look at the Tomcat source code to see what it does and how it does it.
In all but some pretty obscure places it can be treated as a definitive implementation. By the time you find the differences, you'll have enough understanding that you can read and argue about the specification directly.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
rajesh karmani
Greenhorn

Joined: Jun 26, 2001
Posts: 23
Hello,
The reply from Andreas is fully comprehensive. The servlet cotainer calls the generic service method which delegates the call to the http-specific service method by type-casting the arguments in HttpServlet. This method calls the req.getMethod() to determine the doXXX() method.
Rajesh Kumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: service() in HttpServlet