request 获取各种路径
来源:互联网 发布:centos怎么看版本 编辑:程序博客网 时间:2024/06/07 09:50
原文链接:http://zjutsoft.iteye.com/blog/1084260
从request获取各种路径总结
request.getRealPath("url"); // 虚拟目录映射为实际目录
request.getRealPath("./"); // 网页所在的目录
request.getRealPath("../"); // 网页所在目录的上一层目录
request.getContextPath(); // 应用的web目录的名称
如http://localhost:7001/bookStore/
/bookStore/ => [contextPath] (request.getContextPath())
获取Web项目的全路径
String strDirPath = request.getSession().getServletContext().getRealPath("/");
以工程名为TEST为例:
(1)得到包含工程名的当前页面全路径:request.getRequestURI()
结果:/TEST/test.jsp
(2)得到工程名:request.getContextPath()
结果:/TEST
(3)得到当前页面所在目录下全名称:request.getServletPath()
结果:如果页面在jsp目录下 /TEST/jsp/test.jsp
(4)得到页面所在服务器的全路径:application.getRealPath("页面.jsp")
结果:D:\resin\webapps\TEST\test.jsp
(5)得到页面所在服务器的绝对路径:absPath=new java.io.File(application.getRealPath(request.getRequestURI())).getParent();
结果:D:\resin\webapps\TEST
2.在类中取得路径:
(1)类的绝对路径:Class.class.getClass().getResource("/").getPath()
结果:/D:/TEST/WebRoot/WEB-INF/classes/pack/
(2)得到工程的路径:System.getProperty("user.dir")
结果:D:\TEST
3.在Servlet中取得路径:
(1)得到工程目录:request.getSession().getServletContext().getRealPath("") 参数可具体到包名。
结果:E:\Tomcat\webapps\TEST
(2)得到IE地址栏地址:request.getRequestURL()
结果:http://localhost:8080/TEST/test
(3)得到相对地址:request.getRequestURI()
结果:/TEST/test
- request 获取各种路径
- request 获取各种路径
- request 获取各种路径
- request 获取各种路径
- request 获取各种路径
- request获取各种路径
- request 获取各种路径
- request 获取各种路径
- request 获取各种路径
- request 获取各种路径
- request 获取各种路径
- request获取各种路径
- Request获取各种路径
- request 获取各种路径
- request获取各种路径总结
- request获取各种路径方式
- request 获取各种路径【转】
- Request对象获取各种路径
- 用 Keras 编写你的第一个人工神经网络
- 高并发Java 十 JDK8对并发的新支持
- Swift 泛型教程入门
- Mybatis自动生成工具
- 二维码拓展
- request 获取各种路径
- 在Ubuntu上安装并使用DetEval
- 学习curses图形库(一)
- 深入java (类)构造函数和对象创建的内存分配
- Maven多模块项目依赖管理
- js判断为空Null与字符串为空简写方法
- Swift JSON 教程:使用 JSON
- Mysql之ENUM
- jdbc数据库连接知识