1. In Servlet/filter and other servlet web environments, as long as the javax. servlet. servletcontext type is obtained, the path can be obtained through getrealpath. The top-level directory in the relative path can be obtained through the parameter.
Request. getsession (). getservletcontext (). getrealpath ("/");
2. jsp custom tag javax. servlet. jsp. tagext. tagsupport
(Javax. servlet. servletcontext) pagecontext). getrealpath ("");
3. Common Java class object files:
This. getclass (). getresource ("??? ");
If the class file is in the top-level directory (package) and Is a blank string ("), and if this method is executed in the jar file, null is returned. Directories (packages) under the top-level directory (packages) will return URLs containing the protocol. "/" Is used to separate folders (packages) at different layers.
Project location: D:/beyondtrack -- reference/jbpmwebdesigner
Javacode location: D:/beyondtrack -- reference/jbpmwebdesigner/build/web/classes/NET/Java/dev/beyondtrack/web/workflow/DESIGNER/japplet
File Location: D:/beyondtrack -- reference/jbpmwebdesigner/src/Java/NET/Java/dev/beyondtrack/web/workflow/DESIGNER/icon
/*
* To change this template, choose tools | templates
* And open the template in the editor.
*/
Package net. java. Dev. beyondtrack. Web. workflow. Designer. japplet;
Import javax. Swing. imageicon;
/**
*
* @ Author pub32
*/
Public class newmain {
Public newmain (){
System. Out. println (this. getclass (). getresource (""));
System. Out. println (this. getclass (). getresource ("."));
System. Out. println (this. getclass (). getresource (".."));
System. Out. println (this. getclass (). getresource ("/"));
System. Out. println (this. getclass (). getresource ("point.png "));
System. Out. println (this. getclass (). getresource ("/point.png "));
System. Out. println (this. getclass (). getresource ("./point.png "));
System. Out. println (this. getclass (). getresource ("../point.png "));
System. Out. println (this. getclass (). getresource ("icon/point.png "));
System. Out. println (this. getclass (). getresource ("/icon/point.png "));
System. Out. println (this. getclass (). getresource ("./icon/point.png "));
System. Out. println (this. getclass (). getresource ("../icon/point.png "));
}
Public static void main (string [] ARGs ){
System. Out. println ("====== test. Class ==== ");
Newmain test = new newmain ();
}
}
====== Test. Class ======
File:/D:/beyondtrack -- reference/jbpmwebdesigner/build/web/WEB-INF/classes/NET/Java/dev/beyondtrack/web/workflow/DESIGNER/japplet/
File:/D:/beyondtrack -- reference/jbpmwebdesigner/build/web/WEB-INF/classes/NET/Java/dev/beyondtrack/web/workflow/DESIGNER/japplet/
File:/D:/beyondtrack -- reference/jbpmwebdesigner/build/web/WEB-INF/classes/NET/Java/dev/beyondtrack/web/workflow/DESIGNER/
File:/D:/beyondtrack -- reference/jbpmwebdesigner/build/web/WEB-INF/classes/
Null
Null
Null
Null
Null
Null
Null
File:/D:/beyondtrack -- reference/jbpmwebdesigner/build/web/WEB-INF/classes/NET/Java/dev/beyondtrack/web/workflow/DESIGNER/icon/point.png
Build successful (total time: 0 seconds)