关于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(& ...
随机推荐
- Python3 常用模块1
目录 os模块 对文件夹操作 对文件进行操作 sys模块 json 和pickle模块 logging模块 日志等级 longging模块的四大组件 自定义配置 os模块 通过os模块我们可以与操作系 ...
- Linux源码编译安装httpd
Linux安装软件采用源码编译安装灵活自由,适用于不同平台,维护也十分方便. 源码编译的安装方式一般由3个步骤组成: 1.配置(configure) 2.编译(make) 3.安装(make inst ...
- 大数据学习笔记——Hadoop高可用完全分布式模式完整部署教程(包含zookeeper)
高可用模式下的Hadoop集群搭建 本篇博客将会在之前写过的Linux的完整部署的基础上进行,暂时不会涉及到伪分布式或者完全分布式模式搭建,由于HA模式涉及到的配置文件较多,维护起来也较为复杂,相信学 ...
- 《Java基础知识》Java final关键字:阻止继承和多态
在 Java 中,声明类.变量和方法时,可使用关键字 final 来修饰.final 所修饰的数据具有“终态”的特征,表示“最终的”意思.具体规定如下: final 修饰的类不能被继承. final ...
- Poco的介绍和入门教学
版权声明:该文章为AirtestProject原创文章:允许转载,但转载必须注明“转载”并保留原链接 前言 前面我们已经介绍了基于图像识别的测试框架Airtest,通过图像识别,已经可以编写大部分的测 ...
- sqlserver 行转列、字符串行转列、自动生产行转列脚本
行转列,老生常谈的问题.这里总结一下网上的方法. 1.生成测试数据: CREATE TABLE human( name ), --姓名 norm ), --指标 score INT , --分数 gr ...
- vue.config.js的常用配置
const path = require('path') const glob = require('glob') const resolve = (dir) => path.join(__di ...
- 医院信息集成平台(ESB)数据集成建设方案
一.数据资产目录建设 依据卫生部信息化工作领导小组办公室卫生部统计信息中心2011年3月发布的<基于电子病历的医院信息平台建设技术解决方案——业务部分>. 临床服务域 包含12个二级类目: ...
- 更改Android设备System目录的文件的写入权限
有时候我们需要修改/system目录中文件的权限,比如将该目录下的脚本设置写入权限等,但该目录默认只有read权限,此时应该怎么办? 1.安卓设备请确保root;2.连接安卓设备,确保安卓设备打开了“ ...
- JavaScript图形实例:合成花卉图
我们知道在直角坐标系中,圆的方程可描述为: X=R*COS(α) Y=R*SIN(α) 用循环依次取α值为0~2π,计算出X和Y,在canvas画布中将坐标点(X,Y)用线连起来,可绘制出一个圆.编写 ...