获取web工程绝对路径

来源:互联网 发布:软件测试项目经验介绍 编辑:程序博客网 时间:2024/05/19 13:08

  // 获取web工程绝对路径

JAVA WEB ACTION中:

String absPath = new java.io.File(((HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST)).getRealPath("/")).getParent(); System.out.println("+++" + absPath);


JSP:

根目录:request.getRequestURI()
文件的绝对路径  :application.getRealPath(request.getRequestURI());
当前web应用的绝对路径 :application.getRealPath("/");


SERVLET中:

根目录:request.getServletPath();
文件的绝对路径 :
javax.servlet.http.HttpSession.getServletContext()
request.getSession().getServletContext().getRealPath
当前web应用的绝对路径:servletConfig.getServletContext().getRealPath("/");