不通过servlet获取webRoot路径
第一种实现
URL url = ClassLoader.getSystemClassLoader().getResource("./");File file = new File(url.getPath());File parentFile = new File(file.getParent());System.out.println("webRoot:"+parentFile.getParent());
public class Lisiter implment ServletContextListener{ /*通过实现ServletContextAware可获得servletContext*/ private static ServletContext servletContext; @Overridepublic void contextInitialized(ServletContextEvent arg) {this.servletContext=arg.getServletContext();} }
<listener> <listener-class>cn.com.besttone.manage.service.impl.TimeSettleServiceImpl</listener-class> </listener>