• 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

interview question on doget and dopost

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in interview he asked me can we use doget(),dopost() and service method in one servlet?if yes then which method first call?
pl.reply
thanks in advance
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The service method is clearly called first, altough this is transparent when using an HttpServlet. The doGet() and doPost() methods are part of the HttpServlet class.
But to answer the question, (I tried it out just now) you can have an HttpServlet with all 3 methods, and the service method is called first. I am not sure when you have the service method in an HttpServlet, how the doGet or doPost is even called.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks chris for reply .........
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inside the service() method of HttpServlet, it figures out which method to call, based upon the HTTP "method" property, and dispatches to the appropriate doXXX() method. If you override the service() method without calling the superclass' implementation, your servlet will NEVER call the doXXX() method, unless you specifically call it yourself. So, be careful. In general, though, you CAN override multiple doXXX() methods. One reason would be to have the doGet() method render a screen and the doPost() method handle the posting of information FROM that screen and dispatch to another servlet. That way, all of a screen's logic is in one class.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic