一、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. Git 远程分支的查看及相关问题

    命令:git ls-remote -t 或者 git ls-remote --tag 运行结果如下: 0975ebc0f9a6b42ecbe066a50a26a678a0753b4d refs/tag ...

  2. Ubuntu13.04配置完全指南(转)

    Ubuntu13.04配置完全指南(一)软件源 教育网推荐使用USTC软件源. 首先备份现有软件源: $ sudo cp /etc/apt/sources.list /etc/apt/sources. ...

  3. HW3.16

    public class Solution { public static void main(String[] args) { int randomValue = (int)(Math.random ...

  4. PAT 1089. Insert or Merge (25)

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...

  5. ASP.NET MVC- Model- An Introduction to Entity Framework for Absolute Beginners

    Introduction This article introduces Entity Framework to absolute beginners. The article is meant fo ...

  6. SGU107——987654321 problem

    For given number N you must output amount of N-digit numbers, such, that last digits of their square ...

  7. DataTable 导出到 Excel 类

    底层类: #region DataTable 导出到 Excel /// <summary> /// DataTable 导出到 Excel /// </summary> // ...

  8. Oracle Linux 6.3下安装Oracle 11g R2(11.2.0.3)

    本文主要描写叙述了在Oracle Linux 6.3下安装Oracle 11gR2(11.2.0.3).从Oracle 11g開始,Oracle官方站点不再提供其Patch的下载链接,须要使用Meat ...

  9. SQL Server将一列的多行内容拼接成一行的问题讨论

    转自http://blog.csdn.net/rolamao/article/details/7745972 昨天遇到一个SQL Server的问题:需要写一个储存过程来处理几个表中的数据,最后问题出 ...

  10. Mysql性能优化之缓存参数优化

    数据库属于 IO 密集型的应用程序,其主要职责就是数据的管理及存储工作.而我们知道,从内存中读取一个数据库的时间是微秒级别,而从一块普通硬盘上读取一个IO是在毫秒级别,二者相差3个数量级.所以,要优化 ...