Home > Java > Servlet Interview Question

Servlet Interview Question

Q: Explain the life cycle methods of a Servlet.

A: The javax.servlet.Servlet interface defines the tree methods known as life-cycle method.

public void init(ServletConfig config) throws ServletException

public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException

public void destroy()

First the servlet is constructed, then initialized with the init()method.

Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.

The servlet is removed from service, destroyed with the destroy() method, then garbaged collected and finalized.

Categories: Java Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Powered by WP Robot