获取项目根路径

    1. System.out.println("ContextPath:" + request.getContextPath());
    2. // or
    3. System.out.println(this.getServletContext().getContextPath());

    获取Servlet的映射路径

    1. System.out.println("ServletPath:" + request.getServletPath());

    获取当前类的绝对路径

    1. System.out.println("当前类的绝对路径:" + ClassName.class.getResource("/").getPath());

    获取应用的绝对路径

    1. System.out.println(request.getServletContext().getRealPath("/"));