Life cycle methods defined by Servlet interface in javax.servlet package: init, service, destroy

Servlet interface is used to define methods which controls the life cycle of a servlet.

Methods defined by Servlet interface:

init( ) method: It is called by the server when servlet is initialized. Initialization parameters are passed to the servlet. UnavailableException is thrown if servlet was not initialized.


void init(ServletConfig sc) throws ServletException

where, sc has initialization parameters.

service( ) method: It is called by the server to process HTTP request from client.


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

destroy( ) method: It is called by the server to quit resources for a servlet. Data is stored to a persistent storage and memory is garbage collected.


void destroy( )

getServletConfig( ) method: It is used to return a ServletConfig object containing initialization parameters.


ServletConfig getServletConfig( )

Leave a Reply