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

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

<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 
这四个拼装起来,就是当前应用的跟路径了

request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+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 basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

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

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

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

  4. request.getScheme()、 request.getServerName() 、 request.getServerPort() 、 request.getContextPath()

    <% String basePath = request.getScheme() + "://" + request.getServerName() + ":&qu ...

  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 basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+pat----------<base>元素有关

    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request. ...

  8. basePath = request.getScheme()+"://"+request.getServerName()+":"+r

    basePath = request.getScheme()+"://"+request.getServerName()+":"+r (2014-06-30 1 ...

  9. JSP中的:request.getScheme()+"://"+request.getServerName()+":"+request.getServer

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

随机推荐

  1. 解决video.js不兼容ie8问题

    使用视频播放器的时候,常常会让兼容一些浏览器问题,比如兼容ie8浏览器.在工作中使用的是video.js. 如果需要兼容,引入两个js库,就可以做到兼容ie8浏览器 <script src=&q ...

  2. java的各种日志框架

    本文是作者原创,版权归作者所有.若要转载,请注明出处.文章中若有错误和疏漏之处,还请各位大佬不吝指出,谢谢大家. java日志框架有很多,这篇文章我们来整理一下各大主流的日志框架, 包括log4j  ...

  3. CSS(3)---块级标签、行内标签、行内块标签

    块级标签.行内标签.行内块标签 html中的标签元素三种类型:块级标签.行内标签.行内块标签. 一.概述 1.块级标签 概念 每个块元素通常都会独自占据一整行或多整行,可以对其设置宽度.高度.对齐等属 ...

  4. SpringBoot 项目运行在 tomcat7 上

    SpringBoot 项目如何打成 war 包 SpringBoot项目的默认打包方式是将工程打包成为一个 jar 包.部分情况下,我们需要将项目打包成一个 war 包,以方便我们将工程部署在 tom ...

  5. js-07-事件

    一.js事件绑定在对象上的三种方法 a:将事件绑定在元素标签的属性上 <h3 onclick="console.log('奥特曼打怪兽')">海绵宝宝历险记</h ...

  6. zabbix获取一周内各个等级告警的次数

    # encoding:UTF-8 import xlsxwriter import datetime import pymysql import numpy as np import pandas _ ...

  7. rocksdb学习笔记

    rocksdb是在leveldb的基础上优化而得,解决了leveldb的一些问题. 主要的优化点 1.增加了column family,这样有利于多个不相关的数据集存储在同一个db中,因为不同colu ...

  8. Data Guard Physical Standby - RAC Primary to RAC Standby 使用第二个网络 (Doc ID 1349977.1)

    Data Guard Physical Standby - RAC Primary to RAC Standby using a second network (Doc ID 1349977.1) A ...

  9. Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt

    最近安装python,已经安装好,cmd终端中输入python.pip等命令都有用 然而在配置requirements.txt文件过程中,执行语句 “pip install -r requiremen ...

  10. ORM查询(细致):

    ORM查询(细致): 1.正向查找 ret1=model.Book.objects.first() print(ret1.title) print(ret1.price) print(ret1.pub ...