<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

这个语句是用来拼装当前网页的相对路径的。

<base href="...">是用来表明当前页面的相对路径所使用的根路径的。

比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/myblog/authen/login.do

其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。

有了这个 <base ... >以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把 <base ...>指定的路径和页面内的相对路径拼装起来,组成完整路径。

如果没有这个 <base...>,那么我页面的连链接就必须写全路径,否则服务器会找不到。

request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”

request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"

request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80,

request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的myblog

这四个拼装起来,就是当前应用的跟路径了

String path = request.getContextPath的更多相关文章

  1. String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  2. String path = request.getContextPath();这段什么用

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

  3. <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

    <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...

  4. jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

    <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...

  5. jsp页面String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!

    转自:https://blog.csdn.net/kiwangruikyo/article/details/81130311 <%String path = request.getContext ...

  6. 关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

    关于 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+req ...

  7. String path = request.getContextPath();报错

    String path = request.getContextPath();报错 1. 右击该项目 - Build Path - Configure Build Path , 在 Libraries ...

  8. request.getcontextPath() 详解

    request.getcontextPath() 详解 文章分类:Java编程 <%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但 ...

  9. request.getContextPath获取绝对路径

    request.getContextPath获取绝对路径 博客分类: 经验+注意 其他 request.getContextPath 项目需求:所有jsp页必须通过Action转发,不能直接在地址栏链 ...

随机推荐

  1. 【PaddlePaddle系列】手写数字识别

      最近百度为了推广自家编写对深度学习框架PaddlePaddle不断推出各种比赛.百度声称PaddlePaddle是一个“易学.易用”的开源深度学习框架,然而网上的资料少之又少.虽然百度很用心地提供 ...

  2. matplotlib基本使用(矩形图、饼图、热力图、3D图)

    使用matplotlib画简单的图形: #-*- coding:utf-8 -*- from numpy.random import randn import matplotlib.pyplot as ...

  3. Sequel-Model

    Sequel::Model Mass Assignment 大多数的Model方法接受一个包含一系列key和value的哈希作为参数,这些方法包括:Model.new, Model.create, M ...

  4. 数据库 -- Oracle常用命令

    1.查询账号状态 SELECT USERNAME, ACCOUNT_STATUS FROM DBA_USERS; 解锁账号 ALTER USER scott ACCOUNT UNLOCK 2.创建表空 ...

  5. Linux运维中遇到的常见问题

    1.CentOS启动tomcat出现乱码的解决方案1.打开tomcat下的server.xml配置文件,在connect标签中添加编码属性:URIEncoding="UTF-8"2 ...

  6. ASP.NET Core 中的实时框架 SingalR

    目录 SignalR 是什么? 在 ASP.NET Core 中使用 SignalR 权限验证 横向扩展 源代码 参考 SignalR 是什么? ASP.NET Core SignalR 是一个开源的 ...

  7. Week4——结对练习&团队作业1

    Deadline: 2017-10-14 10:00PM,以博客发表日期为准. 评分基准: 按时交 - 有分(结对代码-10分,结对博客-10分,团队博客-10分),检查的项目包括后文的三个方面 按要 ...

  8. c#调用webservices

    有两种方式,静态调用(添加web服务的暂且这样定义)和动态调用: 静态调用: 使用添加web服务的方式支持各种参数,由于vs2010会自动转换,会生成一个特定的Reference.cs类文件   动态 ...

  9. linux使用mail命令发送邮件

    在工作中使用linux,偶尔也会需要使用mail命令来进行发邮件.    从上面的命令看,系统已经安装了mail,对些我们还需要设置一下mail,让它使用外面的邮箱进行发邮件.设置文件是 /etc/m ...

  10. Abp中SwaggerUI的多个接口文档配置说明

    对外提供的接口在实际生成过程中,可能是需要一个接口版本的,比如说v1,manage.效果如下:     在swagger中怎么实现呢? 1. 添加SwaggerVersionHelper.cs pub ...