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.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 + "/";作用!!!!!的更多相关文章
- jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- 关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
关于 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+req ...
- String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";作用!!!!!
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- Struts2中 Path (getContextPath与basePath)
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径. 虽然可以用redirect方式解决,但redirect方式并非必要.解决办法非常简单,统一使用绝对 ...
- jsp页面使用jstl标签格式化String类型日期
1.引入jstl <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> ...
- String path = request.getContextPath();这段什么用
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- JSP页面使用include指令出现 Duplicate local variable basePath
现有三个页面 " include.jsp " " a.jsp " " b.jsp " 页面代码如下 首先是a.jsp <%@ page ...
- JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)
本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...
随机推荐
- 【HDU 5015】233 Matrix
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5015 [算法] 矩阵乘法 [代码] #include<bits/stdc++.h> u ...
- 信息安全-加密:MD5
ylbtech-信息安全-加密:MD5 MD5消息摘要算法(英语:MD5 Message-Digest Algorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值( ...
- [Tomcat]Tomcat6和Tomcat7的区别
Tomcat 7最大的改进是对Servlet 3.0和Java EE 6的支持.◆Tomcat 7完全支持Servlet 3.0规范◆Tomcat 7新增了对Java注释的支持◆Tomcat 7通过w ...
- [jzoj 3175] 数树数 解题报告 (树链剖分)
interlinkage: https://jzoj.net/senior/#main/show/3175 description: 给定一棵N 个节点的树,标号从1~N.每个点有一个权值.要求维护两 ...
- 子线程中刷新了UI
This application is modifying the autolayout engine from a background thread, which can lead to engi ...
- FFmpeg 移植 Android
近期项目需要解析苹果的HLS流媒体协议,而FFmpeg从0.11.1“Happiness”版本开始,才增加了对HLS协议的支持.目前网上关于FFmpeg编译移植的文章有很多,但大多都是对旧版本的说明. ...
- 前端学习笔记-CSS
- Sphinx在windows下安装使用[支持中文全文检索]
原文地址:http://www.fuchaoqun.com/2008/11/sphinx-on-windows-xp/ 前 一阵子尝试使用了一下Sphinx,一个能够被各种语言(PHP/Python/ ...
- 搭建svn服务器(ubuntu)
ubuntu搭建svn服务器 环境:ubuntu 12.04.5 apt-get install subversion 找个目录作为svn的仓库 mkdir svn svnadmin create s ...
- 用IIS怎样在局域网内建网站
IIS服务器组建一览 IIS(Internet Information Server,互联网信息服务)是一种Web(网页)服务组件,其中包括Web服务器.FTP服务器.NNTP服务器和SMTP服务器, ...