1.Java中获取路径的方法: Class_Name.class .getResource("") // Class_Name.class .getResource("/") // 获得当前类所在路径 Java中根路径就是bin
Class_Name.class .getResource("user.dir") // 获得当前类所在路径 Class_Name.class .getResource("java.class.path") // 获得当前类所在路径 2. web项目的根路径是 / JSP中获得当前应用的绝对路径 application.getRealPath("/"); //当前web应用的绝对路径 servlet中获得当前应用的绝对路径 request.getServletPath(); 补充 ServletContext对象获得方式: javax.servlet.http.HttpSession.getServletContext() javax.servlet.jsp.PageContext.getServletContext() javax.servlet.ServletConfig.getServletContext()
web项目中 applicationContext.xml文件,一般放在resource文件夹下面: 然后引用的时候,只需要resource/applicationContext.xml.