import java.io.File; import java.io.IOException; import java.net.URL; public class MyUrlDemo { public static void main(String[] args) { MyUrlDemo muDemo = new MyUrlDemo(); try { muDemo.showURL(); } catch (IOException e) { // TODO Auto-generated catch…
package my; import Java.io.File; import java.io.IOException; import java.net.URL; public class MyUrlDemo { public static void main(String[] args) { MyUrlDemo muDemo = new MyUrlDemo(); try { muDemo.showURL(); } catch (IOException e) { // TODO Auto-gen…
// 第一种:获取类加载的根路径 D:\IDEAWorkspace\hs-bluetooth-lock\src\applications\bluetooth-api\target\classes File f = new File(this.getClass().getResource("/").getPath()); System.out.println(f); // 获取当前类的所在工程路径; 如果不加“/” 获取当前类的加载目录 D:\IDEAWorkspace\hs-bluet…
获取当前类的所在工程路径; 如果不加"/" File f = new File(this.getClass().getResource("").getPath()); System.out.println(f); 结果:C:\Documents%20and%20Settings\Administrator\workspace\projectName\bin\com\test 获取当前类的绝对路径: 第二种:File directory = new File(&quo…
引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. (1):this.getClass().getResource("/"): (2):file.getCanonicalPath(): (3):this.getClass().getClassLoader(): (4):System.getProperty("user.dir&qu…
在HTML页面获取项目根路径的方法: function getRootPath(){ var curPageUrl = window.document.location.href; var rootPath = curPageUrl.split("//")[0] + curPageUrl.split("//")[1].split("/")[0] + curPageUrl.split("//")[1].split("/…
  JavaWeb 获取请求网络协议.IP.端口号.项目根路径 CreateTime--2018年6月1日16点32分 Author:Marydon 1.需求 在项目中,需要使用Java向本程序发送request请求,由于项目的发布名称.部署IP和端口不固定, 如何才能动态获取这些信息呢? 2.代码实现 import javax.servlet.http.HttpServletRequest; /** * 获取url请求前缀 * @explain http://localhost:8080/te…
1.读取项目根路径下的properties文件比较简单也是比较常见的一种操作. 具体代码如下: package com.xuanen.util; import java.util.Properties; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; public class PropertyUtil {…
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp var curWwwPath=window.document.location.href; //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp var pathName=window.document.…
内容来自于snannan_268 关键字: java中获取路径 JAVA中获取路径: 1.jsp中取得路径:   以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.getRequestURI() 结果:/TEST/test.jsp (2)得到工程名:request.getContextPath() 结果:/TEST (3)得到当前页面所在目录下全名称:request.getServletPath() 结果:如果页面在jsp目录下 /TEST/jsp/test.jsp…