在Servlet與JSP中取得當前文件所在的相對路徑與絕對路徑

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

");

String strPathFile = application.getRealPath(request.getRequestURI());

out.println("文件的絕對路徑:" + strPathFile+ "

");

out.println(application.getRealPath(request.getRequestURI()));

String strDirPath = new File(application.getRealPath(request.getRequestURI())).getParent();

out.println("目錄的絕對路徑:" + strDirPath + "

");

%

//Servlet中

//JSP中的application對象就是Servlet中的ServerContext,所以在Servlet中是如此獲得

//import java.io.File;

System.out.println("根目錄所對應的絕對路徑:" + request.getServletPath() + "

");

String strPathFile = request.getSession().getServletContext().getRealPath(request.getRequestURI());

System.out.println("文件的絕對路徑:" + strPathFile + "

");

String strDirPath = new File(request.getSession().getServletContext().getRealPath(request.getRequestURI())).getParent();

System.out.println("目錄的絕對路徑:" + strDirPath + "

");

文件名不能包括以下字符:\/:*?"|

 
 
 
免責聲明:本文為網絡用戶發布,其觀點僅代表作者個人觀點,與本站無關,本站僅提供信息存儲服務。文中陳述內容未經本站證實,其真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考,並請自行核實相關內容。
 
 
© 2005- 王朝網路 版權所有 導航