Can we call destroy() method inside the init() method? What
happens when we do so?
Answer Posted / suraj kumar
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
--------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Servlet</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.esspl.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
------------------------------------
Test URL: http://<HOST>:<PORT>/<Context>/TestServlet.do
| Is This Answer Correct ? | 10 Yes | 4 No |
Post New Answer View All Answers
Define declaration.
What are different Authentication options available in Servlets.
hi actully i hav form columns with origin and destination names .as like as i need to create one more column with name amount. my requirement is when i select origin and destination columns automatically i need to get amount from database.how can i. please tel me with relative code
What is cookie in servlet?
What is servlet instance?
What if you need to span your transaction across multiple servlet invocations?
What do you mean by chaining in servlet?
What are the mechanisms used by a servlet container for maintaining session information?
Explain jsessionid?
What do you mean by servlet context?
What is java servlet?
How many objects of a servlet is created?
What is servlet? Explain
What are its drawbacks of cgi?
What is servlet name in web xml?