Method for obtaining the current absolute path in JSP

xiaoxiao2021-03-06  47

In ASP, we can use server.mappath (".") Directly to the absolute path of the directory where the current program is located (also called physical path), but it seems that there is no direct method in JSP 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 you can 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 ()); out.println;%> In fact, Application object in JSP is the path to ServerContext in servlet is D: / AAA / BBB / CCC / CQQ. JSP is like this, if we don't want the file name behind, 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-81144.html

New Post(0)