Which Servlet life-cycle method is called only once ?
Tripura Public Service Commission - 2026,
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.
Please log in or register to report this question.