<%@ page contentType="text/html;charset=GBK"%><%@ page import="java.io.*" %><%//在Servlet與jsp(SUN企業級應用的首選)中取得當前文件所在的相對路徑與絕對路徑//jsp(SUN企業級應用的首選)中out.println("根目錄所對應的絕對路徑:" + request.getRequestURI() + "
");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(SUN企業級應用的首選)中的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 + "
");文件名不能包括以下字符:/:*?"<>|