SpringMVC request to get the file path

The path 1.java

= Directory File new new File ( " ABC " ); 
 // . "" For getCanonicalPath () function, it means that the current folder, and ".." indicates the current folder on a folder 
directory.getCanonicalPath () ; // get is C: / the Test / abc 
 // for getAbsolutePath () function, regardless, "..", the return current path plus the path you set (when) File in the new new. "" 
Directory. getAbsolutePath (); // get is C: / Test / ABC 
 // As getPath () function, you get only set when the new File () path 
direcotry.getPath (); // get is ABC 
the System . OUT .println (the System.getProperty ( " user.dir " )); // R & lt designates the current path

2.jsp made in the path:

 

To project called TEST , for example:

// (1) get the current page contains the full path name of the project: 
request.getRequestURI () // result: /TEST/test.jsp 
 // (2) to get the project name: 
request.getContextPath () // result: / TEST 
 // (3) to get the current page directory full name: 
request.getServletPath () // result: If the page in jsp directory /TEST/jsp/test.jsp 
 // full path (4) to get the server where the page: 
application.getRealPath ( " page .jsp " ) // result: D: /resin/webapps/TEST/test.jsp 
 // (5) get the absolute path to the server where the page: 
ABSPATH = new new java.io.File (the Application. the getRealPath (Request.getRequestURI ())) getParent ();. // results: D: / resin / webapps / TEST

 

3. path made in class:

// (1) in the absolute path: 
Class. Class .getClass () the getResource (. " / " ) .GetPath () // Results: / D: / the TEST / the WebRoot / the WEB-INF / classes / Pack / 
 // (2) to get the project path: 
System.getProperty ( " user.dir " ) // result: D: / TEST

 

4. path made in a Servlet:

// (1) to get the project directory: 
. Request.getSession () getServletContext () getRealPath ( ""). // result: E: / Tomcat / webapps / the TEST 
 // (2) get IE address bar Address: 
request.getRequestURL () // results: HTTP: // localhost : 8080 / the TEST / Test 
 // (. 3) obtained relative address: 
Request.getRequestURI () // results: / TEST / test

 

Guess you like

Origin www.cnblogs.com/yysbolg/p/11102010.html