我看到了很多的源代碼,開發人員在ServletContextListener來實現(例如)編碼方式類似於下面是ServletContext的-的removeAttribute中的ServletContextListener,contextDestroyed需要
public class ServletContextListenerImpl implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
sce.getServletContext().setAttribute("attribute1", new Bean1());
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
sce.getServletContext().removeAttribute("attribute1"); //--- LINE_REMOVE
}
我的問題是,我們真的需要有行標「LINE_REMOVE 「在上面的例子中?
我想我們不需要它,因爲當contextDestroyed執行時,servletContext即將完全銷燬,所以它的屬性也會被刪除。
感謝您的想法。
謝謝。我接受了你的想法。 – Loc