Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which Servlet life-cycle method is called only once ?

  • A.init()
  • B.services()
  • C.destroy()
  • D.doGet()

Answer: A

The keyed answer is init().

The servlet container calls init() exactly once, after it creates the servlet object and before the first request, to let the servlet set itself up. service() (the printed option reads services()) and the handlers doGet() and doPost() run once for every request.

One caution: destroy() is also called only once, when the container removes the servlet. The question does not exclude it, but the key and the usual textbook answer to 'called only once' is init(), the one-time initialisation method, so that is the answer given.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.