javaweb基础 01--JSP取得绝对路径应用
2024-10-15 11:46:44
1.相关函数说明
* request.getScheme() 等到的是协议名称,默认是http * request.getServerName() 得到的是在服务器的配置文件中配置的服务器名称 比如:localhost .baidu.com 等等 * request.getServerPort() 得到的是服务器的配置文件中配置的端口号 比如 8080等等 * request.getContextPath() 返回站点的根目录 * request.getRealpath("/")得到的是实际的物理路径,也就是你的项目所在服务器中的路径
2.用法示例
<%
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort();
String path = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort() + request.getContextPath()
+ "/";
String filePath=path+"resources/";
session.setAttribute("path", path);
session.setAttribute("basePath", basePath);
session.setAttribute("filePath", filePath);
%> 以上这段代码的project name是drp5.1,可在tomcat下的webapp目录下找到该目录。
其中 request.getContextPath() = /drp5.1
basePath = http://localhost:8080
path = http://localhost:8080/drp5.1/
filePath = http://localhost:8080/drp5.1/resources/
最新文章
- Google软件构建工具Bazel FAQ
- Sublime写MarkDown实时预览
- 基于淘宝弹性布局方案lib-flexible的问题研究
- bootstrap学习笔记系列4------bootstrap按钮
- Cheatsheet: 2014 02.01 ~ 02.28
- Python 字典(Dictionary) setdefault()方法
- windows 配置免安装 node
- tomcat context 配置 项目部署
- session问题和JSP
- C#中常量\枚举\结构及数组的运用
- Python相关项目和技术
- sql+PHP基础+面向对象基础简单总结
- strace ->; System call tracer
- 搭建webpack基础配置
- VS2010添加虚拟机发布的WebService引用
- mysql 8.0.12 创建新的数据库、用户并授权
- python - socketserver 模块应用
- CF 954H Path Counting
- websocket服务器握手协议
- 【Logstash系列】使用Logstash作为收集端采集IIS日志