一、java获取web工程路径

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();

  <!--EndFragment-->

<%
//此方法是通用的,可以获取不同系统中应用项目的根目录
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() +  path + "/";
%>

二、js获取web工程路径

       var strFullPath=window.document.location.href;
         var strPath=window.document.location.pathname;
         var pos=strFullPath.indexOf(strPath);
         var prePath=strFullPath.substring(0,pos);
         var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
         var webPath=prePath+postPath;

java ,js获取web工程路径的更多相关文章

  1. JS 获取WEB请求路径

    function getRealPath(){      //获取当前网址,如: http://localhost:8083/myproj/view/my.jsp       var curWwwPa ...

  2. java 或者 js 获取项目访问路径(域名)

    /** * 获得站点url * @return */ public String getWebUrl(){ String url = getRequest().getScheme() + " ...

  3. Java中获取项目根路径和类加载路径的7种方法

    引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. ...

  4. js获取项目根路径

    //js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost ...

  5. Servlet之ServletContext获取web上下文路径、全局参数、和Attribute(域)

    1)获取web上下文路径 public void doGet(HttpServletRequest request, HttpServletResponse response) throws Serv ...

  6. 获取web应用路径 // "/" 表示class 根目录

    /** * 获取web应用路径 * @Description : 方法描述 * @Method_Name : getRootPath * @return * @return : String * @C ...

  7. JAVA,JSP,Servlet获取当前工程路径-绝对路径

    在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getPro ...

  8. java中获取各种上下文路径的方法小结

    一.获得都是当前运行文件在服务器上的绝对路径在servlet里用:this.getServletContext().getRealPath(); 在struts用:this.getServlet(). ...

  9. 【转】Spring 获取web根目录 (Spring线程获取web目录/路径/根目录,普通类获取web目录)

    不使用Spring,怎样能在Listener启动的Thread中获取web目录,还真不完全确定.其实我觉得实际代码也很简单.就是基于普通的listener,然后在listener中获取web目录并放到 ...

随机推荐

  1. sap判断条件

    EQ  等于=  等于NE  不 等于<>  不 等于><  不 等于LT  小 于<  小于LE  小 于等于<=  小 于等于GT  大 于>  大于GE ...

  2. POJ3280 - Cheapest Palindrome(区间DP)

    题目大意 给定一个字符串,要求你通过插入和删除操作把它变为回文串,对于每个字符的插入和删除都有一个花费,问你把字符串变为回文串最少需要多少花费 题解 看懂题立马YY了个方程,敲完就交了,然后就A了,爽 ...

  3. CF_216_Div_2

    比赛链接:http://codeforces.com/contest/369 369C - Valera and Elections: 这是一个树上问题,用深搜,最开始贪心想得是只加叶子节点,找到一个 ...

  4. Cassandra的登录认证授权

    cassandra的登录验证机制是独自的,数据是集群共享的 参考:http://blog.csdn.net/y_y_y_k_k_k_k/article/category/5943357 1.初始安装启 ...

  5. 东芝超级本从win8到win7

    东芝超级本从win8到win7 2014年2月20日 11:08:46   1. 进入BIOS     调出关机选项,按住shift不松手,然后点选关机,彻底关机后,按住f2不松手,按下电源开机,就进 ...

  6. MSSQLSERVER数据库- 字符串分割函数返回类型表

    遇到这样一个问题,存储在数据库的数据是一串字符串如:1,2,3,4,5,6.想把这串字符串进行转变成一个表格,如下: 1 2 3 4 5 6 就是这样一个问题,有人同事,写了一个这样的封装函数,这样就 ...

  7. 正则表达式_matches(Regex)

    [0-9a-zA-Z.%+-] 匹配中括号中的 0-9 或者 a-z 或者 A-Z 或者 . 或者 % 或者 + 或者 - $p = "111,222,333"$p -match ...

  8. C socket demo

    一.服务端-server.c #include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> # ...

  9. UVA Knight Moves

    题目例如以下: Knight Moves  A friend of you is doing research on the Traveling Knight Problem (TKP) where ...

  10. android颜色对应的xml配置值,颜色表

    网上找的一些颜色值 XML配置 <?xml version="1.0" encoding="utf-8" ?> <resources> ...