This article describes the JSP to obtain the current directory implementation methods, share for everyone to reference. The implementation methods are as follows:
1, using the System.getproperty () function to get the current path:
Copy Code code as follows:
System.out.println (System.getproperty ("User.dir"));//user.dir specified the current path
2, use the function provided by the file to get the current path:
Copy Code code as follows:
File directory = new file ("");//Set as current folder
try{
System.out.println (Directory.getcanonicalpath ());//Get the standard path
System.out.println (Directory.getabsolutepath ());//Get absolute path
}catch (Exceptin e) {}
File.getcanonicalpath () and File.getabsolutepath () are about just the new File (".") and new File ("..") There is a difference between these two paths.
# for the Getcanonicalpath () function, "." Represents the current folder, and the "..." Represents the folder up to the current folder
# for the GetAbsolutePath () function, regardless of ".", "...", return the current path plus the path you set at New File ()
# As for the GetPath () function, you get only the path you set at New File ()
For example, the current path is c:test:
Copy Code code as follows:
File directory = new file ("abc");
Directory.getcanonicalpath (); Got a c:testabc.
Directory.getabsolutepath (); Got a c:testabc.
Direcotry.getpath (); I got ABC.
File directory = new file (".");
Directory.getcanonicalpath (); Got a c:test.
Directory.getabsolutepath (); Get the c:test.
Direcotry.getpath (); Get is.
File directory = new file ("..");
Directory.getcanonicalpath (); Get the C:
Directory.getabsolutepath (); Get the c:test.
Direcotry.getpath (); Get a..
Get the current working directory for JAVA Programs
Copy Code code as follows:
File File = new file ("T.tmp");
String FullPath = File.getabsolutepath ();
①request.getrealpath:
Method: Request.getrealpath ("/")
The resulting path: C:Program filesapache Software foundationtomcat 5.5webappsstrutsTest
Method: Request.getrealpath (".")
The resulting path: C:Program filesapache Software foundationtomcat 5.5webappsstrutsTest.
Method: Request.getrealpath ("")
The resulting path: C:Program filesapache Software foundationtomcat 5.5webappsstrutsTest
Method: Request.getrealpath ("Web.xml")
The resulting path: C:Program filesapache Software foundationtomcat 5.5webappsstrutstestweb.xml
②request.getparameter ("");
Actionform.getmyfile ();
Method: String filepath = request.getparameter ("MyFile");
The resulting path: D:vss installation directory Users.txt
Method: String filepath = Actionform.getmyfile ();
The resulting path: D:vss installation directory Users.txt
I hope this article will help you with the JSP program design.