<% @ Page contentType = "text/html; charset = GBK" %> <% @ page import = "java. io. * "%> <% // obtain the relative path and absolute path of the current file in Servlet and jsp (preferred for SUN Enterprise Applications) // jsp (preferred for SUN Enterprise applications) medium out. println ("absolute path corresponding to the root directory:" + request. getRequestURI () +"
"); String strPathFile = application. getRealPath (request. getRequestURI (); out. println (" absolute path of the file: "+ strPathFile +"
"); Out. println (application. getRealPath (request. getRequestURI (); String strDirPath = new File (application. getRealPath (request. getRequestURI ())). getParent (); out. println ("absolute directory path:" + strDirPath +"
"); %> // The application object in the Servlet // jsp (preferred for SUN Enterprise Applications) is the ServerContext In the Servlet, so it is obtained in the Servlet // import java. io. file; System. out. println ("absolute path corresponding to the root directory:" + request. getServletPath () +"
"); String strPathFile = request. getSession (). getServletContext (). getRealPath (request. getRequestURI (); System. out. println ("absolute path of the file:" + strPathFile +"
"); String strDirPath = new File (request. getSession (). getServletContext (). getRealPath (request. getRequestURI ())). getParent (); System. out. println ("absolute directory path:" + strDirPath +"
"); The file name cannot contain the following characters :/:*? "<> |