經常使用的監聽器 servletContextListener、httpSessionListener、servletRequestListener,關於各個 listener 的做用,這裏不作介紹ide
監聽器實例:code
@WebListener public class MyListener implements ServletRequestListener { @Override public void requestDestroyed(ServletRequestEvent sre) { System.out.println("MyListener....requestDestroyed..."); } @Override public void requestInitialized(ServletRequestEvent sre) { System.out.println("MyListener....requestInitialized..."); } }
啓動類中加入下面一行註解:servlet
@ServletComponentScan