1. 程式人生 > >JAVA獲得當前tomcat服務的專案的絕對路徑

JAVA獲得當前tomcat服務的專案的絕對路徑

request.getSession().getServletContext().getRealPath("") ;

在括號內不寫斜線,是為了保證在Windows和liunx中同時適用。

輸出:

Windows:D:/apache-tomcat-9.0.0/webapps/ROOT

liunx:/usr/tomcat/apache-tomcat-9.0.12