jboss 獲取web專案真實路徑

_hug發表於2014-06-12

上傳圖片,圖片儲存路徑為專案所在目錄,

因為tomcat和jboss的容器實現不一樣(具體的不清楚...),在jboss中request.getSession().getServletContext().getRealPath結果為null

so:


String qq1 = TVShop3Controllor.class.getResource("/").getFile();

String qq2 = Thread.currentThread().getContextClassLoader().getResource("/").getPath();
String qq3 = Thread.currentThread().getContextClassLoader().getResource("").getPath();
System.out.println("qq1:"+qq1);
System.out.println("qq2:"+qq2);
System.out.println("qq3:"+qq3);
String realPath = request.getSession().getServletContext().getRealPath("/positionImage"); 

System.out.println("realPath:"+realPath);



qq1: /F:/javaneeds/workplace/0526/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ott-web-in/WEB-INF/classes/

qq2: /F:/javaneeds/workplace/0526/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ott-web-in/WEB-INF/classes/

qq3: /F:/javaneeds/workplace/0526/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ott-web-in/WEB-INF/classes/

realPath: F:\javaneeds\workplace\0526\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ott-web-in\positionImage

相關文章