转自:https://blog.csdn.net/kiwangruikyo/article/details/81130311

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

jsp页面String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!的更多相关文章

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

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

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

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

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

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

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

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

  5. Struts2中 Path (getContextPath与basePath)

    struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径. 虽然可以用redirect方式解决,但redirect方式并非必要.解决办法非常简单,统一使用绝对 ...

  6. jsp页面使用jstl标签格式化String类型日期

    1.引入jstl <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> ...

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

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

  8. JSP页面使用include指令出现 Duplicate local variable basePath

    现有三个页面 " include.jsp " " a.jsp " " b.jsp " 页面代码如下 首先是a.jsp <%@ page ...

  9. JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)

    本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...

随机推荐

  1. 0x26 广搜变形

    电路维修 这道题虽然乍一看就会想斜对角的两点之间边权受初始电路的影响要么为0要么为1,但是有一个思考点就是可以通过奇偶性,证明相邻的两个点是不可能在同一个电路中.练习一下双端队列. #include& ...

  2. [转]Linux+XAMPP+eolinker开源版v3.2.4

    eolinker是一个由国人开源的接口管理系统(AMS),特性及介绍详见开源中国-eolinker首页. 搭建步骤参考:eolinker开源指南 系统环境:CentOS Linux release 7 ...

  3. Neo4j下执行cypher-shell时,Connection refused问题解决?

    不多说,直接上干货!  问题现象 root@zhouls-/bin# ls cypher-shell neo4j neo4j-admin neo4j-import neo4j-shell tools ...

  4. appium连接夜游神的方法

    很多小伙伴想连接夜游神模拟器,但是无法连接,下面是夜游神的链接方法 第一步:先打开夜游神模拟器 第二步:打开运行输入cmd,输入夜游神连接方法:adb connect 127.0.0.1:62001第 ...

  5. 利用PBFunc在Powerbuilder中进行FTP操作

    PBFunc.dll包含了FTP的操作,使用FTP时主要需要以下步骤: 1.调用of_Login函数登录Ftp服务器 2.调用FTP的各种方法 3.Ftp操作完毕后调用of_LoginOut方法进行注 ...

  6. DataTables入门

    转载 https://blog.csdn.net/gfd54gd5f46/article/details/65938189

  7. Python多线程原理与实现

    Date: 2019-06-04 Author: Sun Python多线程原理与实战 目的: (1)了解python线程执行原理 (2)掌握多线程编程与线程同步 (3)了解线程池的使用 1 线程基本 ...

  8. JSP获取json格式的数据报错 Uncaught SyntaxError: Unexpected identifier

    后台json字符串是 {"id":"cmdb_ci.`fully_qualified_domain_name`","field":" ...

  9. CentOS 7最小安装配置网络

    安装环境: VMware Workstation14 centos 7.5.1804 最小化安装 安装过程: 在系统安装成功后进行网络配置,我这里采用的是动态ip配置.首先得知道网络配置存放的目录: ...

  10. python之类与对象属性的增删改查

    类属性与对象属性的增删改查 类属性的增删改查 class School: """ 文档 """ Teacher = "老王&quo ...