Method for obtaining the current absolute path in JSP

xiaoxiao2021-03-06  27

[转] http://blog.9cbs.net/fanboy2001/Archive/2004/12/11/213290.aspx

In ASP, we can take directly to the absolute path of the current program where the current program is located (also called physical path).

However, in JSP, there is no direct method to get the absolute path of the current directory.

Request.getRealPath () just got the absolute path corresponding to the root directory, read the servlet API document, found that

Get the absolute path name of the current file in this way, such as writing this in my CQQ.JSP file:

<% String strabspath = Application.getRealPath (Request.getRequesturi ()); out.println (strabspath);%>

In fact, the Application object in JSP is ServerContext in servlet.

The path to this is d: /aaa/bb/ccc/cqq.jsp, if we don't want the file name behind,

That is, we want to get D: / AAA / BBB / CCC / this path, we can use the File class directly.

The complete statement should be like this:

String strabspath = new java.io.file (Application.getRealpath ())). GetParent ();

转载请注明原文地址:https://www.9cbs.com/read-81618.html

New Post(0)