js中获取 <%=request.getContextPath()%>
来源:互联网 发布:点播软件哪个好 编辑:程序博客网 时间:2024/06/03 20:58
参考地址:http://hexudonghot.blog.163.com/blog/static/532043422012112264411234/
在jsp中获取context path或者basePath 是很容易的。在javascript中也可以获取,并且有的时候也很有必要。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
在单独的javascript中不能使用<%= basePath%>类似这样的java script所以,只能用javascript来获取此context path.
可以用下面的代码来实现。
var localObj = window.location;
var contextPath = localObj.pathname.split("/")[1];
var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath;
var server_context=basePath;
两种实现的方法用在不同的环境中。
0 0
- [js]js中获取 <%=request.getContextPath()%>
- js中获取 <%=request.getContextPath()%>
- js中获取 <%=request.getContextPath()%>
- 转载【js中获取 <%=request.getContextPath()%>】
- js中获取 <%=request.getContextPath()%>
- request.getContextPath获取绝对路径
- 通过request.getContextPath获取绝对路径
- %=request.getContextPath() %解释
- <%=request.getContextPath()%>
- <%=request.getContextPath()%>
- String path = request.getContextPath();获取应用的上下文路径。
- ${pageContext.request.contextPath}|request.getContextPath() 项目路径怎么在js(jquery)中获得
- <%=request.getContextPath()%>的作用
- String path = request.getContextPath
- <%=request.getContextPath()%>的作用
- <%=request.getContextPath()%>的作用
- request.getContextPath()获取的是什么路径?
- request.getContextPath()获取的是什么路径?
- iOS中的文件管理操作
- Viewpager和fragment和自定义的底部Tab实现切换效果
- Javascript模块化编程(二):AMD规范
- Linux守护进程
- 关于C语言中二级指针的理解
- js中获取 <%=request.getContextPath()%>
- 清除android程序中的多余资源
- 使用filter2D创建自定义线性滤波器
- JAVA NIO 简介
- 【从头开始写操作系统系列】环境搭建以及第一个Hello World
- 360网盘资料如何存放到隐形云中
- g++的编译及调试
- EL表达式里面fn的用法
- APM,云时代的应用性能优化神器