监听器获取项目路径

package cn.com.tonbu.common.listener;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class ZahyContextListener implements ServletContextListener {

public static final Map<String, String> map = new HashMap<String, String>();

@Override
public void contextDestroyed(ServletContextEvent sce) {
map.clear();
System.out.println("销毁-+----------------------------------------------------------");
}

@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
sc.setAttribute("contextPath", sc.getRealPath("/"));
map.put("contextPath", sc.getRealPath("/"));
System.out.println(sc.getRealPath("/"));
}

}













web.xml



<listener>
<listener-class>cn.com.tonbu.common.listener.ZahyContextListener</listener-class>
</listener>

猜你喜欢

转载自417755712.iteye.com/blog/2261053
今日推荐