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/

最新文章

  1. Google软件构建工具Bazel FAQ
  2. Sublime写MarkDown实时预览
  3. 基于淘宝弹性布局方案lib-flexible的问题研究
  4. bootstrap学习笔记系列4------bootstrap按钮
  5. Cheatsheet: 2014 02.01 ~ 02.28
  6. Python 字典(Dictionary) setdefault()方法
  7. windows 配置免安装 node
  8. tomcat context 配置 项目部署
  9. session问题和JSP
  10. C#中常量\枚举\结构及数组的运用
  11. Python相关项目和技术
  12. sql+PHP基础+面向对象基础简单总结
  13. strace -&gt; System call tracer
  14. 搭建webpack基础配置
  15. VS2010添加虚拟机发布的WebService引用
  16. mysql 8.0.12 创建新的数据库、用户并授权
  17. python - socketserver 模块应用
  18. CF 954H Path Counting
  19. websocket服务器握手协议
  20. 【Logstash系列】使用Logstash作为收集端采集IIS日志

热门文章

  1. Intellij MyBatisPlus Plugin插件破解
  2. Yii2.0 to(), toRoute(), current()区别用法
  3. 几个免费IP地址查询API接口
  4. Mac terminal Javac
  5. Xcode密钥没有备份或者证书过期,出现Valid Signing错误
  6. 关于Struts2的文件下载
  7. Objective-C 语法之 NSURL
  8. jsavascript 面向对象的下拉菜单
  9. Redis Cluster 简单安装配置
  10. mysql操作类