首先在web.xml中我们需要配置监听器,如下所示
<listener>
<listener-class>com.a.listener.WordListener</listener-class> </listener>然后我们需要编写监听类com.a.listener.WordListener
public class WordListener implements ServletContextListener{ @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub } //监听器初始化运行的方法 @Override public void contextInitialized(ServletContextEvent arg0) { // TODO Auto-generated method stub try { //syso } catch (Exception e) { // TODO: handle exception } } }