js 中获取上下文路径
2015-10-06 22:56
369 查看
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp var curWwwPath=window.document.location.href; //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp var pathName=window.document.location.pathname; var pos=curWwwPath.indexOf(pathName); //获取主机地址,如: http://localhost:8083 var localhostPaht=curWwwPath.substring(0,pos); //获取带"/"的项目名,如:/uimcardprj var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1); return(localhostPaht+projectName); }微商城中使用到了:single.js
var curWwwPath=window.document.location.href; var pathName=window.document.location.pathname; var pos=curWwwPath.indexOf(pathName); //获取主机地址,如: http://localhost:7070 var localhostPaht=curWwwPath.substring(0,pos); //alert(localhostPaht); this.uploadUrl = localhostPaht +"/shop/weixin/ajaxUploadPic";
============================华丽的分隔符============================
java中获取
Map<String, Object> map = new HashMap<String, Object>(); map.put("url", request.getContextPath() +"/weixin/business_single?sessionId="+sessionId);
最终的结果:http:localhost:8080/shop/weixin/business_single?sessionId=1234
转自:/article/2004990.html
相关文章推荐
- 在jsp页面中使用CKEditor
- 解决 js 中文乱码问题小技巧
- 2015-10-05 js3
- JavaScript高级程序设计第23章(离线应用与客户端存储)
- JS获取当前/指定URL参数
- JS 封装
- javascript原来还可以这样玩
- Json 解析
- Extjs extjs datefield日期格式
- javascript创建对象常用方法
- JS 闭包
- JSP include
- JavaScript基本语法(2)
- JSP过滤器导图详解
- 2015-09-29 js2
- JackSon——轻松解析Json/XML数据
- FastJson——生成和解析Json数据
- JS 变量作用域
- seajs3.0模块加载原理及源码注释
- javascript的介绍,实现和输出以及语法-javascript学习之旅(1)