获取web应用路径 // "/" 表示class 根目录
/**
* 获取web应用路径
* @Description : 方法描述
* @Method_Name : getRootPath
* @return
* @return : String
* @Creation Date : 2013-12-13 下午9:09:28
* @version : v1.00
* @throws UnsupportedEncodingException
* @Author : zyn
* @Update Date :
* @Update Author : zyn
*/
public static String getRootPath() throws UnsupportedEncodingException {
String classPath = WebHelper.class.getClassLoader().getResource("/").getPath();
// "/" 表示class 根目录
String rootPath = "";
// windows下
if ("\\".equals(File.separator)) {
rootPath = classPath.substring(1, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("/", "\\");
rootPath = URLDecoder.decode(rootPath, "UTF-8");
}
// linux下
if ("/".equals(File.separator)) {
rootPath = classPath.substring(0, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("\\", "/");
rootPath = URLDecoder.decode(rootPath, "UTF-8");
}
return rootPath;
}
获取web应用路径 // "/" 表示class 根目录的更多相关文章
- java ,js获取web工程路径
一.java获取web工程路径 1),在servlet可以用一下方法取得: request.getRealPath(“/”) 例如:filepach = request.getRealPath(“/” ...
- Servlet之ServletContext获取web上下文路径、全局参数、和Attribute(域)
1)获取web上下文路径 public void doGet(HttpServletRequest request, HttpServletResponse response) throws Serv ...
- 【转】Spring 获取web根目录 (Spring线程获取web目录/路径/根目录,普通类获取web目录)
不使用Spring,怎样能在Listener启动的Thread中获取web目录,还真不完全确定.其实我觉得实际代码也很简单.就是基于普通的listener,然后在listener中获取web目录并放到 ...
- Java获取web项目路径
File f = new File(WebPath.class.getResource("/").getPath()); String path = f.getParentFile ...
- 获取web服务器路径的方法 getResourceAsStream
1.先获取 serlvetContext对象 2.调用getResourceAsStream 在方法里 "\"表示当前web的根目录 还要拼接上具体的文件路径 ServletC ...
- JS 获取WEB请求路径
function getRealPath(){ //获取当前网址,如: http://localhost:8083/myproj/view/my.jsp var curWwwPa ...
- C#里面获取web和非web项目路径
非Web程序获取路径几种方法如下: 1.AppDomain.CurrentDomain.BaseDirectory 2.Environment.CurrentDirectory 3.HttpRunt ...
- ASP.NET获取web应用程序的路径
服务器磁盘上的物理路径: HttPRuntime.AppDomainAppPath虚拟程序路径: HttpRuntime.AppDomainAppVirtualPath 任何于Request/Http ...
- 【转】Java Web 项目获取运行时路径 classpath
Java Web 项目获取运行时路径 classpath 假设资源文件放在maven工程的 src/main/resources 资源文件夹下,源码文件放在 src/main/java/下, 那么ja ...
随机推荐
- 谈谈dpdk应用层包处理程序的多进程和多线程模型选择时的若干考虑
看到知乎上有个关于linux多进程.多线程的讨论:http://www.zhihu.com/question/19903801/answer/14842584 自己项目里也对这个问题有过很多探讨和测试 ...
- FileInputStream读取文件&FileOutputStream写入文件
概念摘自:http://jingyan.baidu.com/article/5552ef473ab5f2518ffbc98e.html Java的流式输入输出建立在4个抽象类的基础上:InputStr ...
- MPchartAnadroid的对比柱状图
1.导入三方jar包(可参照) MPAndroidChart(GitHub上优秀得图表功能库) MPAndroidChart常见设置属性(一)——应用层 2.布局activity_main.xml(这 ...
- python里如何计算大文件的md5
在python3中,有了一个hashlib,可以用来计算md5,这里先给出一个简单的例子: import hashlib sstr="i love hanyu" print(has ...
- MYSQL的longtext字段能放多少数据?
生产上遇到问题, 同事说MYSQL里的字段放不下5m大小的数据. 于是,将django model里textfield里的max_length变长了. 依然无效, 于是,更改mysql的设置: set ...
- Codeforces 839 B. Game of the Rows-贪心
最近太zz了,老是忘记带脑子... 补的以前的cf,发现脑子不好使... B. Game of the Rows time limit per test 1 second memory lim ...
- Codeforces Round #262 (Div. 2) A. Vasya and Socks【暴力/模拟/袜子在可以在合法情况下增加后用几天】
A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 线性基【p4570】 [BJWC2011]元素
题目描述-->p4570 [BJWC2011]元素 题目大意 给定一些矿石的编号与价值,我们想要得到最大的价值和,并且选定物品的编号异或之和不为0. 分析 线性基就不多bb了,来这里->p ...
- 【视频】Linux高级程序设计01.3命令行选项及参数
[课程笔记] [命令行参数] 选项:-l -a -i 参数:-l /home main 函数形式: int main(int argc, char *argv[]) main函数是有参数的,而且有返回 ...
- Nand flash uboot 命令详解
转:http://blog.chinaunix.net/uid-14833587-id-76513.html nand info & nand device 显示flash的信息: DM365 ...