web项目中各种路径的获取
来源:互联网 发布:focusky for mac 破解 编辑:程序博客网 时间:2024/06/05 04:02
以工程名为/DemoWeb为例:
访问的jsp为:http://localhost:8080/DemoWeb/test/index.jsp
1 JSP中获得当前应用的相对路径和绝对路径
(1)得到工程名:request.getContextPath()
结果:/DemoWeb
(2)得到包含工程名的当前页面全路径:request.getRequestURI()
结果:/DemoWeb/test/testpath.jsp
(3)得到IE地址栏地址:request.getRequestURL()
结果:http://localhost:8080/DemoWeb/test/testpath.jsp
(4)得到当前页面所在目录下全名称:request.getServletPath()
结果:/test/testpath.jsp
(5)得到页面所在服务器的全路径(实际的路径):application.getRealPath("testpath.jsp")
结果:D:\Develop Files\apache-tomcat-5.5.15\apache-tomcat-5.5.15\webapps\DemoWeb\testpath.jsp
D:\Develop Files\apache-tomcat-5.5.15\apache-tomcat-5.5.15为tomcat的安装路径
2.java 的Class中获得相对路径,绝对路径的方法
(1)类的绝对路径:
System.out.println(TestPath.class.getResource("/").getPath());
结果:/E:/workspace/workspace_tcc/DemoWeb/WebRoot/WEB-INF/classes/
System.out.println(TestPath.class.getResource(""));
结果:file:/E:/workspace/workspace_tcc/DemoWeb/WebRoot/WEB-INF/classes/demo1/
(2)得到工程的路径:System.getProperty("user.dir")
访问的jsp为:http://localhost:8080/DemoWeb/test/index.jsp
1 JSP中获得当前应用的相对路径和绝对路径
(1)得到工程名:request.getContextPath()
结果:/DemoWeb
(2)得到包含工程名的当前页面全路径:request.getRequestURI()
结果:/DemoWeb/test/testpath.jsp
(3)得到IE地址栏地址:request.getRequestURL()
结果:http://localhost:8080/DemoWeb/test/testpath.jsp
(4)得到当前页面所在目录下全名称:request.getServletPath()
结果:/test/testpath.jsp
(5)得到页面所在服务器的全路径(实际的路径):application.getRealPath("testpath.jsp")
结果:D:\Develop Files\apache-tomcat-5.5.15\apache-tomcat-5.5.15\webapps\DemoWeb\testpath.jsp
D:\Develop Files\apache-tomcat-5.5.15\apache-tomcat-5.5.15为tomcat的安装路径
2.java 的Class中获得相对路径,绝对路径的方法
(1)类的绝对路径:
System.out.println(TestPath.class.getResource("/").getPath());
结果:/E:/workspace/workspace_tcc/DemoWeb/WebRoot/WEB-INF/classes/
System.out.println(TestPath.class.getResource(""));
结果:file:/E:/workspace/workspace_tcc/DemoWeb/WebRoot/WEB-INF/classes/demo1/
(2)得到工程的路径:System.getProperty("user.dir")
结果:E:\workspace\workspace_tcc\DemoWeb
阅读全文
0 0
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- static 相关的知识点
- Hadoop完全分布式集群安装Spark
- 数据结构第三次上机 第四章之顺序串
- 【viewPager实现轮播(代码)】
- 优化 UWP 中图片的内存占用
- web项目中各种路径的获取
- wpi http 报错
- 非常详细的 Docker 学习笔记
- shell中的字母大小写转换
- hbase filter及rowkey范围检索使用并对结果集处理
- SAP Fiori 2.0中文版系列视频教程(中文首发)
- c++语言的空格问题
- 从控制层返回到js的json数据带“\”转译符,怎么去掉
- 对抗神经网络,梦,潜意识