当前位置: 代码迷 >> Web前端 >> web项目,取得根路径,在普通类中
  详细解决方案

web项目,取得根路径,在普通类中

热度:102   发布时间:2012-12-23 11:28:15.0
web项目,获得根路径,在普通类中
/**
  * 得到WebRoot文件夹下的根路径,及web项目的根路径
  * @return
  */
  public  String getWebRootAbsolutePath() {  
         String path = null;  
         String folderPath = Path.class.getProtectionDomain().getCodeSource()  
                 .getLocation().getPath();  
         if (folderPath.indexOf("WEB-INF") > 0) {  
             path = folderPath.substring(0, folderPath  
                     .indexOf("WEB-INF"));   
         }  
         return path;  
}  

?

  相关解决方案