Weblogic war包部署时获取Web根目录问题
2016-07-18 16:14
239 查看
在Weblogic当中如果以war包方式部署则不能用request.getRealPath(“/”)获取web根目录,
/**
* 获取web目录,Weblogic 默认以war包部署的时候不能用getRealPath
* getResource("/")获取的是当前应用所在的类路径,截取到WEB-INF
* 之后的路径就是当前应用的web根目录了
* @param request
* @return
*/
public String getDocumentRoot(HttpServletRequest request){
String webRoot = request.getSession().getServletContext().getRealPath("/");
if(webRoot == null){
webRoot = this.getClass().getClassLoader().getResource("/").getPath();
webRoot = webRoot.substring(0,webRoot.indexOf("WEB-INF"));
}
return webRoot;
}
this.getClass().getClassLoader().getResource("/").getPath()即可获取:
/**
* 获取web目录,Weblogic 默认以war包部署的时候不能用getRealPath
* getResource("/")获取的是当前应用所在的类路径,截取到WEB-INF
* 之后的路径就是当前应用的web根目录了
* @param request
* @return
*/
public String getDocumentRoot(HttpServletRequest request){
String webRoot = request.getSession().getServletContext().getRealPath("/");
if(webRoot == null){
webRoot = this.getClass().getClassLoader().getResource("/").getPath();
webRoot = webRoot.substring(0,webRoot.indexOf("WEB-INF"));
}
return webRoot;
}
相关文章推荐
- log4的配置和使用
- leetcode_c++:链表:Remove Linked List Elements(203)
- HDU 1564 考虑奇偶性的变化
- java数组遍历——iterator和for方法
- 分布式缓存技术redis学习(四)——redis高级应用(集群搭建、集群分区原理、集群操作)
- 第二周实习总结
- Hadoop 中文编码相关问题 -- mapreduce程序处理GBK编码数据并输出GBK编码数据(转)
- 【HDU 2717】Catch That Cow(BFS)
- 如何解决Win10 Win7 无法通过\\访问winxp文件
- JavaScript强化教程——JavaScript 运算符
- ubuntu16.04 SVN的安装与使用
- 关于TextView 中设置一行显示字数的两个属性: maxEms 与 maxLength
- Oracle意外删除数据文件恢复方法
- Comparator 与Comparable 异同
- HDOJ 1236 排名
- Ubuntu 开机自启动工具 update-rd.d 使用详解
- Mysql 安装-操作-备份
- android:windowSoftInputMode属性使用
- nyoj 927部分求和问题
- 如何正确地写出单例模式