首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

转:java获取根途径有两种方式

2012-08-30 
转:java获取根路径有两种方式http://java.chinaitlab.com/net/818899.html java获取根路径有两种方式:  1)

转:java获取根路径有两种方式
http://java.chinaitlab.com/net/818899.html
 
java获取根路径有两种方式:

  1),在servlet可以用一下方法取得:

 

 request.getRealPath(“/”) 例如:filepach = request.getRealPath(“/”)+”//upload//”;

  2),不从jsp,或servlet中获取,只从普通java类中获取:

 
 String path =   getClass().getProtectionDomain().getCodeSource().getLocation().getPath();  SAXReader()  saxReader = new SAXReader();  if(path.indexOf(“WEB-INF”)>0){  path = path.substring(0,path.indexOf(“/WEB-INF/classes”)+16);  //  ‘/WEB-INF/classes’为16位  document = saxReader.read(path+filename);  }else{  document = saxReader.read(getClass().getResourceAsStream(filename));  }


  weblogic   tomcat 下都有效

  
String path =   getClass().getProtectionDomain().getCodeSource().getLocation().getPath();

热点排行