File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interview question on doget and dopost

 
vicky baba
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Chris Hall
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
kapil bhate
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks chris for reply .........
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic