转发重定向用到的绝对路径 String path = request.getContextPath
来源:互联网 发布:微信酒店订房系统源码 编辑:程序博客网 时间:2024/06/05 08:19
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
这个语句是用来拼装当前网页的相对路径的。
是用来表明当前页面的相对路径所使用的根路径的。
比如,页面内部有一个连接,完整的路径应该是 http://localhost:80/myblog/authen/login.do
其中http://server/是服务器的基本路径,myblog是当前应用程序的名字,那么,我的根路径应该是那么http://localhost:80/myblog/。
有了这个 以后,我的页面内容的连接,我不想写全路径,我只要写 authen/login.do就可以了。服务器会自动把 指定的路径和页面内的相对路径拼装起来,组成完整路径。
如果没有这个 ,那么我页面的连链接就必须写全路径,否则服务器会找不到。
request.getSchema()可以返回当前页面使用的协议,就是上面例子中的“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是上面例子中的“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是80,
request.getContextPath()可以返回当前页面所在的应用的名字,就是上面例子中的myblog
这四个拼装起来,就是当前应用的跟路径了
function fanhui(){ alert("<%=basePath%>"); alert("<%=path%>");//1. window.self.location = "<%=basePath%>/index.html";//2. location.href='javascript:history.go(-1)'; }
- 转发重定向用到的绝对路径 String path = request.getContextPath
- String path = request.getContextPath
- String path = request.getContextPath();获取应用的上下文路径。
- JSP创建时的<% String path = request.getContextPath();%>
- String path = request.getContextPath路径问题
- String Path = request.getContextPath()报错
- request转发、重定向
- String path = request.getContextPath(); JSP中的相对Path的设置
- String path = request.getContextPath();JSP中的相对Path的设置
- String path = request.getContextPath(); JSP中的相对Path的设置
- request的重定向和转发
- JSP中语句<% String path = request.getContextPath(); String basePath...的含义
- String path = request.getContextPath();这段什么用
- String path = request.getContextPath(....拼装当前网页的相对路径
- jsp文件中<% String path = request.getContextPath(); %>语句的作用
- String path = request.getContextPath(拼装当前网页的相对路径 )
- String path = request.getContextPath(....拼装当前网页的相对路径
- String path = request.getContextPath(....拼装当前网页的相对路径
- 数据结构--哈夫曼树建立及打印编码
- 第二章 第六课 Scratch作品:摇摇晃晃的虫子(随机数和碰到边缘就反弹)
- android:windowSoftInputMode属性详解
- js下如何弹出保存对话框进行文件下载
- Conerstone破解版安装后提示“已损坏”问题
- 转发重定向用到的绝对路径 String path = request.getContextPath
- f_read 函数
- Session
- 改善程序员生活质量的 3+10 习惯
- 深度学习第四课第一周--卷积神经网络(随笔)
- 类中的静态成员变量和静态成员函数的作用
- Spring Boot 连接MySql数据库
- 决策树ID3和C4.5的区别
- 数据库索引和B-tree的联系