在Servlet與JSP中取得當前文件所在的相對路徑與絕對路徑
//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 + "
");
文件名不能包括以下字符:\/:*?"<>|