In Asp, we can use Server. Mappath (".") to directly obtain the absolute path (also called the physical path) of the directory where the current program is located ),
However, in jsp (the preferred choice for SUN Enterprise applications), there seems to be no direct way to obtain the absolute path of the current directory.
Request. getRealPath () is only the absolute path corresponding to the root directory. After reading the Servlet API documentation, you can
Obtain the absolute path name of the current file in this way, for example, in my cqq. jsp (preferred for SUN Enterprise Applications) file:
<%
String strAbsPath = application. getRealPath (request. getRequestURI ());
Out. println (strAbsPath );
%>
In fact, the application object in jsp (the preferred choice for SUN Enterprise Applications) is the ServerContext in Servlet.
The obtained path is D: aaabbccccqq. jsp (preferred for SUN Enterprise Applications). If we do not want the file name,
If we want to get the path D: aaabbccc, we can use the File class directly.
The complete statement should be as follows:
String strAbsPath = new java. io. File (application. getRealPath (request. getRequestURI (). getParent ();