主要步骤如下:
1、建一个自己的监听器实现ServletContextListener接口;
2、实现contextInitialized方法,在此方法中加载配置文件信息;
3、在web.xml中配置监听器的信息。
实例代码如下:
public class WebAppEventListener implements ServletContextListener
{
@Override
public void contextInitialized(ServletContextEvent sce)
{
final ServletContext context = sce.getServletContext();
String path = context.getRealPath("/");
MyApplication.initlize(path);
}
}
public class MyApplication {
private static String webPath = null;
private static String xxxxxx;
public static void initlize(String webPath) {
MyApplication.webPath = webPath;
//app.properties放在resource根目录下
InputStream is = MyApplication.class.getClassLoader().getResourceAsSt