eclipse 建tomcat project 如何在代码里获得tomcat的ROOT路径? eclipsetomcat 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ROOT路径?楼主是要获取classpath的路径吗?使用 Thread.currentThread().getContextClassLoader().getResource("/").getPath(); 参考 java代码中获取classpath路径 我取得的值是:/E:/workspace/HotelCloud/WebRoot/WEB-INF/classes/ , 而不是我想要的D:\apache-tomcat-7.0.54\webapps\ROOT 的路径 Thread.currentThread().getContextClassLoader().getResource("/").getPath(); 取得就是你要的路径,你试试看。楼主试过 Thread.currentThread().getContextClassLoader().getResource("/").getPath(); 这个代码了吗?取得是哪个路径呢? 我就是用你的代码获取的路径,结果是:/E:/workspace/HotelCloud/WebRoot/WEB-INF/classes/ ,我建的是tomcat工程,不是web工程,没能取到D:\apache-tomcat-7.0.54\webapps\ROOT 的路径 等等,你的代码在哪里运行呢?D:\apache-tomcat-7.0.54\webapps\ROOT 中?你建的是tomcat工程?不大理解,楼主详细说一下。那你试试java本身的 System.getProperty("user.dir") 取到的路径 等等,你的代码在哪里运行呢?D:\apache-tomcat-7.0.54\webapps\ROOT 中?你建的是tomcat工程?不大理解,楼主详细说一下。那你试试java本身的 System.getProperty("user.dir") 取到的路径我的代码是运行在我的工作空间,就是D盘的workspace,因为是tomcat工程,所以不会在tomcat安装目录下的webapp目录下存在这个工程,而是直接运行在我的工作空间,这就导致了我在servlet里通过request.getServletContext().getrealpath()取得的路径是E:/workspace/HotelCloud/WebRoot,而不是tomcat 安装目录的webroot路径 String filepath = this.getServletContext().getRealPath(""); 如何实现下来框中显示我当前页面的页号 取值问题 急用 求救,JSP,Struts1.2下ActionMessages使用的问题 接收邮件时如何只获取新邮件? hibernate异常,两天了还没解决 无扩展名文件保存时自动加..txt扩展名是怎么回事 如何利用JavaMail 接收html格式的邮件 服务器主动删除session问题 下载tomcat后怎么办?(急) 关于Tag库,有疑问请进。 配上shiro后@autowried注解失效,求大神! 如何在前端弹出提示框
使用 Thread.currentThread().getContextClassLoader().getResource("/").getPath();
参考 java代码中获取classpath路径
我取得的值是:/E:/workspace/HotelCloud/WebRoot/WEB-INF/classes/ , 而不是我想要的D:\apache-tomcat-7.0.54\webapps\ROOT 的路径
我就是用你的代码获取的路径,结果是:/E:/workspace/HotelCloud/WebRoot/WEB-INF/classes/ ,我建的是tomcat工程,不是web工程,没能取到D:\apache-tomcat-7.0.54\webapps\ROOT 的路径
你建的是tomcat工程?不大理解,楼主详细说一下。
那你试试java本身的 System.getProperty("user.dir") 取到的路径
你建的是tomcat工程?不大理解,楼主详细说一下。
那你试试java本身的 System.getProperty("user.dir") 取到的路径我的代码是运行在我的工作空间,就是D盘的workspace,因为是tomcat工程,所以不会在tomcat安装目录下的webapp目录下存在这个工程,而是直接运行在我的工作空间,这就导致了我在servlet里通过request.getServletContext().getrealpath()取得的路径是E:/workspace/HotelCloud/WebRoot,而不是tomcat 安装目录的webroot路径