关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
关于
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 和
String basePath=http://localhost:8080/ 等同
开始学java的时候看不懂为什么这么写,今天复习的时候才搞懂:这个语句是用来拼接当前网页的相对路径的。
<base herf="...">从来表明当前页面的相对路径所使用的根路径,也就是项目名称
比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/Info_System/user/user_info.jsp
其中http://server/是服务器的基本路径,Info_System是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:8080/Info_System/。
用这个base,服务器就可以动态的将指定路径和页面的相对路径拼装起来,形成完整的路径。
1.request.getSchema();可以返回当前页面所使用的协议,就是"http"
2.request.getServerName();返回当前页面所在服务器的名字,就是上面例子中的"localhost"
3.request.getServerPort();返回当前页面所在服务器的端口号,就是上面例子中的"8085"
4.request.getContextPath();返回当前页面所在的应用的名字,就是上面例子中的"Info_System"
当前页面路径是:http://localhost:80/Info_System/uploadAttachs/attachs_list.jsp
根据上面的介绍,那么我在当前页面中有跳转为: <li><a href="<%=basePath%>user/user_info.jsp" class="information_off"></a></li>就应该这样写。
转载于: https://blog.csdn.net/haocm66/article/details/52998785
关于String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";的更多相关文章
- 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()+"://"+re ...
- jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- 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 ...
- Struts2中 Path (getContextPath与basePath)
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径. 虽然可以用redirect方式解决,但redirect方式并非必要.解决办法非常简单,统一使用绝对 ...
- String path = request.getContextPath();这段什么用
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...
- request.getcontextPath() 详解
request.getcontextPath() 详解 文章分类:Java编程 <%=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径. 但 ...
- JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)
本随笔这是作为一个记录使用,以备后查.项目完成之后本地部署OK,本地Linux部署OK,都可以正常的访问,可是当我把它部署到服务器上面的时候,首页可以正常访问,可是当发出请求的时候却报错误了,说找不到 ...
- request.getContextPath()
今天终于明白了jsp中的request.getContextPath()是怎么回事了. request.getContextPath() 返回站点的根目录 request.getRealpath(& ...
随机推荐
- ubuntu文件权限
以root身份登录linux. 在某一目录下执行 ls -al,显示类似如下内容: dr-xr-x---. 14 root root 4096 Aug 27 09:38 . dr-xr-xr-x. 2 ...
- 《JavaScript 模式》知识点小抄本(上)
介绍 最近开始给自己每周订个学习任务,学习结果反馈为一篇文章的输出,做好学习记录. 这一周(02.25-03.03)我定的目标是<JavaScript 模式>的第七章学习一遍,学习结果的反 ...
- dockerfile-格式和使用
一.dockerfile格式 Dockerfile是一个包含用于组合映像的命令文本文档,可以使用在命令行中调用任何命令,Docker通过读取dockerfile中的指令自动生成映像.docker bu ...
- JS数据结构——队列
创建一个自己的类来表示一个队列 function Queue() { //这里写属性和方法 } 首先需要一个用于存储队列中元素的数据结构,可以用数组 let items = [] 接下来声明一些队列可 ...
- Oracle 12C CDB、PDB常用管理命令
Oracle 12C CDB.PDB常用管理命令 --查看PDB信息(在CDB模式下) show pdbs --查看所有pdbselect name,open_mode from v$pdbs; ...
- 【NodeJS】nvm
[NodeJS]nvm node多版本管理 NVM_HOME=C:\env\nvm NVM_SYMLINK=C:\env\nodejs 查看版本 nvm v 查看当前使用的node版本 nvm cur ...
- cordova 打包出现transformClassesWithDexForDebug一类错误的解决办法
Cordova在添加了插件后,或者是本身文件很多,文件很大的情况下打包时候可能会出现 transformClassesWithDexForDebug或者transformClassesWithDexF ...
- HPS端的GPIO如何控制
该笔记主要记录HPS端的GPIO如何控制,包括控制LED和Key 1.GPIO地址映射 Peripheral Base Address 0xf000_0000 64M 2.HPS外设 (1)GPIO ...
- webpack学习2.2webpack简介,初步了解
webpack V1功能进化 编译打包 HMR(模块热更新) 代码分割 文件处理(loader) webpack V2功能进化 tree shaking(并欸有在项目中使用的代码不会打包到里面,打包之 ...
- 《Javascript设计模式与开发实践》--读书笔记
第2章 this call apply bind()方法创建一个新的函数,在bind()被调用时,这个新函数的this被bind的第一个参数指定,其余的参数将作为新函数的参数供调用时使用. bind( ...