Posted on 2008-04-10 10:28
wind_miao 阅读(229)
评论(0) 编辑 收藏 所属分类:
Servlet&JSP
//JSP中
<%
out.println("根目录所对应的绝对路径:" + request.getRequestURI() + "<br/>");
String strPathFile = application.getRealPath(request.getRequestURI());
out.println("文件的绝对路径:" + strPathFile + "<br/>");
String strDirPath = new File(application.getRealPath(request.getRequestURI())).getParent();
out.println("目录的绝对路径:" + strDirPath + "<br/>");
%>
//Servlet中
//JSP中的application对象就是Servlet中的ServerContext,所以在Servlet中是如此获得
System.out.println("根目录所对应的绝对路径:" + request.getServletPath());
String strFullPath = request.getSession().getServletContext().getRealPath("");
System.out.println("目录的绝对路径" + strFullPath);
String strContextPath = request.getContextPath();
System.out.println("获得Web项目的上下文路径" + strContextPath);
System.out.println("获取访问站点的相对路径" + request.getRequestURI());
System.out.println("获取访问站点的绝对路径" + request.getRequestURL());