Question { Ericsson, 21320 }
Can we call destroy() method inside the init() method? What
happens when we do so?
Answer
This action does not disturb the normal life cycle flow of the servlet. The servlet will work normal. You may test the below code.
/**
* @author Suraj
*
*/
public class TestServlet extends HttpServlet {
public void init(ServletConfig config)throws ServletException{
super.init(config);
destroy();
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("I am test servlet.");
}
}
Web.xml
--------------------------------------
Servlet
TestServlet
com.esspl.TestServlet
TestServlet
*.do
------------------------------------
Test URL: http://
://TestServlet.do