获取项目根路径
System.out.println("ContextPath:" + request.getContextPath());
// or
System.out.println(this.getServletContext().getContextPath());
获取Servlet的映射路径
System.out.println("ServletPath:" + request.getServletPath());
获取当前类的绝对路径
System.out.println("当前类的绝对路径:" + ClassName.class.getResource("/").getPath());
获取应用的绝对路径
System.out.println(request.getServletContext().getRealPath("/"));