当我关闭服务器时,在 Eclipse 中不会调用 destroy()。
public class Demo extends GenericServlet {
public void init(ServletConfig config) throws ServletException{
System.out.println("intit intialized");
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
System.out.println("servicccceeeeeeeee method........");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<h1>service method</h1>");
out.close();
}
public void destroy() {
System.out.printlnln(".........destroy method invoked.......");
}
}
何时以及如何调用 destroy 方法?
最佳答案
当您突然 完全终止 整个 Java 虚拟机时,它不会被调用。 IE。当您按下 Eclipse 控制台选项卡中的红色方形按钮时。
当您轻轻停止或重新启动服务器本身时,它将被调用。 IE。当您按下 Eclipse 服务器选项卡中的红色方形按钮时。
关于java - 如何从eclipse调用servlet中的destroy()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31850551/