Posted on 2008-04-10 10:28
wind_miao 閱讀(233)
評論(0) 編輯 收藏 所屬分類:
Servlet&JSP
//JSP中
<%
out.println("根目錄所對應(yīng)的絕對路徑:" + 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("根目錄所對應(yīng)的絕對路徑:" + request.getServletPath());
String strFullPath = request.getSession().getServletContext().getRealPath("");
System.out.println("目錄的絕對路徑" + strFullPath);
String strContextPath = request.getContextPath();
System.out.println("獲得Web項(xiàng)目的上下文路徑" + strContextPath);
System.out.println("獲取訪問站點(diǎn)的相對路徑" + request.getRequestURI());
System.out.println("獲取訪問站點(diǎn)的絕對路徑" + request.getRequestURL());