服务器--Tomcat获取同级目录

实例代码

//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同级目录tomcatPath=E:\JAGO\Softwares\LearningSoftwares\apache-tomcat-7.0.52

你可能感兴趣的:(P1:服务器)