1.需求:很多时候,在一个 web 项目启动的时候,我们都要【初始化很多系统参数,比如读取配置文件】,或者初始化数据库表...
2.解决方法:实现【 ServletContextListener】 接口
2.1.把实现了ServletContextListener 的类配置到【 web.xml】 文件中
web.xml文件添加:
<listener>
<listener-class>com.chinaso.init.StartInit</listener-class>
</listener>
监听类实现 ServletContextListener接口
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("初始化成功---------");
//createTable_2();
}