//1.项目路径 String projectPath = request.getSession().getServletContext().getRealPath("/"); //2.tomcat同级路径 String tomcatPath = new File(projectPath ).getParentFile().getParentFile().getAbsolutePath(); //3.打印测试 System.out.println("项目路径projectPath =" + projectPath ); System.out.println( "Tomcat同级目录tomcatPath=" + tomcatPath); |
我的测试打印结果为:
项目真实路径relPath=E:\Justin\Softwares\LearningSoftwares\apache-tomcat-7.0.52\webapps\TestSSM\
Tomcat同级absolutePath=E:\JAGO\Softwares\LearningSoftwares\apache-tomcat-7.0.52