获取服务器classes根路径
/**
* 获取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 = Object.class.getClass().getResource("/").getPath();
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;
}
获取服务器classes根路径的更多相关文章
- Java Web获取Web应用根路径
最基本的 1,request.getRealPath("/");这个方法已不推荐用 2,在Servlet 里用this.getServletContext().getRealPat ...
- js获取系统的根路径实现介绍
js如何获取系统的根路径,在本文给出了详细的方法 function getBasePath(){ var obj=window.location; var contextPath=obj.pathna ...
- js获取当前项目根路径URL (转自CSDN 红领巾-sunlight)
/** * //获取当前项目根路径 * @return {TypeName} */ function getRootPath(){ //获取当前网址,如: http://localhost:8083/ ...
- js获取网站项目根路径
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...
- 在HTML页面中获取当前项目根路径的方法
在HTML页面获取项目根路径的方法: function getRootPath(){ var curPageUrl = window.document.location.href; var rootP ...
- asp获取虚拟目录根路径
<% TempArray = Array("account_book","admin","ajaxFile","catalo ...
- jsp笔记----jsp常用的的获取项目的根路径
<% String path = request.getContextPath(); String basePath = request.getScheme() + "://" ...
- 在java web中获取该项目的根路径
在jsp页面中: <% String path = application.getRealPath("").replace("\\","\\\\ ...
- python 获取项目的根路径
root_path = os.path.abspath(os.path.dirname(__file__)).split('shippingSchedule')[0] shippingSchedule ...
随机推荐
- Shader剔除像素绘制扇形
Shader "Custom/Indicator" { Properties { _MainTex("Main Texture", 2D) = "wh ...
- CentOS7.3系统启动故障修复
CentOS7.3系统启动故障修复 破解CentOS7的root口令方法一 启动时任意键暂停启动菜单,选择启动内核菜单项 按 e 键进入编辑模式 将光标移动 linux16 开始的行,添加内核参数rd ...
- BZOJ 3150 [Ctsc2013]猴子 ——期望DP 高斯消元
一堆牌的期望等于每张牌的期望值和. 考虑三个人的游戏即可得到. 然后每张牌遇到另外一张的概率相同,然后就可以列方程求解了. #include <cmath> #include <cs ...
- 【CCF】JSON查询
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- Python 安装MySQLdb模块遇到报错及解决方案:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
一.问题 系统:win7 64位 在下载MySQL-python-1.2.5.zip,使用python setup.py install 安装时,出现以下报错: _mysql.c(42) : fata ...
- pom.xml(Project Object Model) 文件简单介绍
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- JS - caller,callee,call,apply [transfer] aA ==> apply uses an array [] as the second argument. call uses different argument.
在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments : 该对象代表正在执行的函数和调用它的函数的参数. [function.]argument ...
- Selenium2+python自动化(unittest)
# coding:utf-8from selenium import webdriverimport unittestimport timeclass Bolg(unittest.TestCase): ...
- TP5 多条件whereOr查询
问题背景:最近在用ThinkPHP 5开发项目的过程中,发现根据筛选条件做or查询的时候,连贯操作不可以使用where进行条件查询了. 首先列出一个user数据表的信息: uid uname grad ...
- (1)WCF托管
wcf 托管方式有很多种,常见的托管方式,iis,was,控制台,winfrom等. 先创建一个wcf服务 IService1.cs using System.ServiceModel; namesp ...