String webPath = request.getServletPath();

log.info(webPath);

输出:

/zjdlbb/zjdlbb/zjdlbb/test.ht

log.info(request.getServletContext().getRealPath("/"));

输出:

E:\Program Files (x86)\workspace\oms\web\

String webPath = request.getContextPath();

log.info(webPath);

输出:/oms

// 使用相对目录的方式读取文件,相对目录即是项目的目录

File file = new File("src" + File.separator + "dom"

+ File.separator + "xml" + File.separator + "class.xml");

File file2 = new File(DomDemo.class.getClassLoader()

.getResource("").getPath().substring(1)

+ "dom"

+ File.separator

+ "xml"

+ File.separator

+ "class.xml");

//当前路径

System.out.println(Demo01.class.getResource("."));//   file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/

System.out.println(Demo01.class.getResource(""));//    file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/

System.out.println(Demo01.class.getResource(".").getPath());//   /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/

System.out.println(Demo01.class.getResource("").getPath());//    /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/demo01/

//根目录

System.out.println(Demo01.class.getResource("/"));//   file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/

System.out.println(Demo01.class.getResource("/").getPath());//      /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/

//项目路径

System.out.println(System.getProperty("user.dir"));//  D:\Program\workspace\freemarker

System.out.println(Demo01.class.getClassLoader().getResource("."));//  file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/

System.out.println(Demo01.class.getClassLoader().getResource(""));//  file:/D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/

System.out.println(Demo01.class.getClassLoader().getResource(".").getPath());//  /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/

System.out.println(Demo01.class.getClassLoader().getResource("").getPath());//  /D:/Program/workspace/freemarker/WebRoot/WEB-INF/classes/

关于获取路径path的更多相关文章

  1. 获取路径path

    request 的常用方法 request.getSchema() 返回当前页面使用的协议,http 或是 https; request.getServerName() 返回当前页面所在的服务器的名字 ...

  2. Android根据图片Uri获取图片path绝对路径的几种方法【转】

    在Android 编程中经常会用到Uri转化为文件路径,如我们从相册选择图片上传至服务器,一般上传前需要对图片进行压缩,这时候就要用到图片的绝对路径. 下面对我开发中uri转path路径遇到的问题进行 ...

  3. java中获取路径的几种基本的方法

    package com.ygh.blog.realpath; import java.io.File; import java.io.IOException; import java.io.Input ...

  4. JavaEE 获取路径全攻略

    本篇博客是 JavaWeb 应用服务器端在不同环境下获取文件路径的全面总结. 获取文件路径后主要应用的场景,读取 JavaWeb 自定义配置文件.在特定路径下生成各种类型的文件提供下载...... 想 ...

  5. C#项目打开/保存文件夹/指定类型文件,获取路径

    C#项目打开/保存文件夹/指定类型文件,获取路径 转:http://q1q2q363.xiaoxiang.blog.163.com/blog/static/1106963682011722424325 ...

  6. find_first_of()和 find_last_of() 【获取路径、文件名】

    find_first_of()和 find_last_of() [获取路径.文件名](2011-06-11 12:44:46)转载▼标签: 杂谈 分类: c  string 类提供字符串处理函数,利用 ...

  7. Java文件获取路径方式:

    转自:http://blog.csdn.net/appleprince88/article/details/11599805# 谢谢! 由于经常需要获取文件的路径,但是比较容易忘记,每次需要总需要查询 ...

  8. Java获取路径方法&相对路径读取xml文件方法

    (1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI ...

  9. java中获取路径中的空格处理(%20)问题

    在java中获取文件路径的时候,有时候会获取到空格,但是在中文编码环境下,空格会变成“%20”从而使得路径错误. 解决办法: String path = Parameter.class.getReso ...

随机推荐

  1. 显示windows的音频的输入输出设备

    #include "stdafx.h" /************************音频的输入输出设备**************************/ #include ...

  2. 解决在html中引入font-awesome的css文件后, 图标显示不出来

    今天小颖在做项目时,需要在html文件中引入font-awesome.min.css,但是引入后: 以前小颖在用font-awesome库里的图标时,都是直接从node中下包,然后在main.js中引 ...

  3. linux命令学习(4):cd命令

    Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的.所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. 1. 命 ...

  4. Unity3D Shader 模型流光效果

    Shader "Custom/FlowColor" { Properties { _MainTex ("Base (RGB)", 2D) = "whi ...

  5. python3之文件操作

    一   打开文件   根目录在d盘的文件名为‘学习资料.txt’的文件 a)绝对路径(最开始的,根目录文件)例:    e:\学习资料.txt 相对路径   直接用文件名字 b)操作方式  只读  只 ...

  6. 命名空间与Autoload

    命名空间是为了防止函数名冲突 当php编译器找到未定义类时,就会自动去调用__autoload($class)这个函数,$class就代表这个未定义的类名相对于当前项目根目录所在路径   php5.3 ...

  7. 正则表达式、re模块

    正则表达式 一说规则我已经知道你很晕了,现在就让我们先来看一些实际的应用.在线测试工具 http://tool.chinaz.com/regex/ 正则表达式是用来匹配字符串非常强大的工具,在其他编程 ...

  8. python数据类型之pandas—DataFrame

    DataFrame定义: DataFrame是pandas的两个主要数据结构之一,另一个是Series —一个表格型的数据结构 —含有一组有序的列 —大致可看成共享同一个index的Series集合 ...

  9. GMM-实现聚类的代码示例

    Matlab 代码: % GMM code function varargout = gmm(X, K_or_centroids) % input X:N-by-D data matrix % inp ...

  10. hive中的几个参数:元数据配置、仓库位置、打印表字段相关参数

    hive仓库位置由以下参数决定,默认位置/user/hive/warehouse: <property>         <name>hive.metastore.wareho ...