• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

service() in HttpServlet

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The latter, really. The container implements the service method so that it calls the appropriate doXXX method. The service method should never be overriden.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But which service() method it calls.
service(ServletRequest req,ServletResponse res)
or
service(HttpServletRequest req,HttpServletResponse res)
Thanks & Regards
Mike
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Raj Paul
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hoo cool...
Thanks & Regards
Mike
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Doug,
I didnt get ur question, see tomcat source code ?
Thanks & Regards
Mike
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic