A. java,獲取已發布tomcat項目的原始地址路徑

String dir = request.getServletContext().getRealPath("/");
request怎麼來的就不多說了吧!!

B. tomcat啟動時就java類就獲取tomcat伺服器路徑

String path = null;
File file = new File(".");
try {
path = file.getCanonicalPath();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

這個path就是TOMCAT\BIN目錄

C. 如何在java類里獲取tomcat容器的絕對路徑=

可以通過「 類名.class.getResource("").getPath()」方法實現。

D. 如何獲取tomcat下的webapps的絕對路徑呢

//獲取當前項目的絕對路徑

public String getPorjectPath(){

String nowpath; //當前tomcat的bin目錄的路徑 如 D:\java\software\apache-tomcat-6.0.14\bin

String tempdir;

nowpath=System.getProperty("user.dir");

tempdir=nowpath.replace("bin", "webapps"); //把bin 文件夾變到 webapps文件裡面

tempdir+="\\"+projectName; //拼成D:\java\software\apache-tomcat-6.0.14\webapps\sz_pro

return tempdir;

}

E. 求助,java如何獲取項目在tomcat的根路徑

如果已經有系統環境變數的話,就用System.getEnv("TOMCAT_ROOT"),當然你要自定義TOMCAT_ROOT到系統變數裡面。

F. java 獲取tomcat 目錄

需要放在webinf下的classes中
它自動載入時會把你的txt文件自動載入到webinf下的classes中去的。你想要取到路徑的話
通過當前的類的class再得到getresoues路徑名就可以了
xmlutils.class.getresource(filepath).getpath();我是這樣得到了。

G. 如何通過Java代碼獲取tomcat伺服器的絕對路徑

//也許有你想要的,前提是在項目布署運行起來後,在servlet中或controller中運行以下代碼即可。
System.out.println(this.getClass().getResource("/"));//結果:file:/E:/work/service/tomcat7.0.65/webapps/mvc_adminlte/WEB-INF/classes/
System.out.println(System.getProperty("catalina.home"));//結果:E:workservice omcat7.0.65
System.getProperty("user.dir");//結果:E:workservice omcat7.0.65in
System.out.println(request.getSession().getServletContext().getRealPath("/"));//結果:E:workservice omcat7.0.65webapps你的項目名稱
希望能幫到你!

H. 在java程序中獲得Tomcat下的webapps絕對路徑的程序怎麼寫

jsp中:request.getContextPath()
servlet、action中:
HttpSession session = request.getSession();
ServletContext application = session.getServletContext();
String serverRealPath = application.getRealPath("/") ;