What is the life cycle of a servlet?
-
init(),service(),destroy()
-
init(),destroy(),service(),
-
init(),process(),destroy()
-
init(),start(),destroy()
Reveal answer
Fill a bubble to check yourself
A
Correct answer
Explanation
The servlet lifecycle follows init() for initialization, service() for processing requests, and destroy() for cleanup. The service() method is called repeatedly for each request until the servlet is destroyed.
AI explanation
A servlet's lifecycle is controlled by the container, which calls init() once to initialize the servlet, then service() for every incoming request (dispatching to doGet/doPost internally), and finally destroy() once when the servlet is being unloaded. There's no separate process() or start() method in the Servlet API, which is why those distractors are wrong.