获取context path或者basePath
转自: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;
两种实现的方法用在不同的环境中。
获取context path或者basePath的更多相关文章
- 如何获取path与basePath
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding=& ...
- Android根据图片Uri获取图片path绝对路径的几种方法【转】
在Android 编程中经常会用到Uri转化为文件路径,如我们从相册选择图片上传至服务器,一般上传前需要对图片进行压缩,这时候就要用到图片的绝对路径. 下面对我开发中uri转path路径遇到的问题进行 ...
- struts2中错误There is no Action mapped for namespace [/] and action name [] associated with context path
1 There is no Action mapped for namespace [/] and action name [] associated with context path [/Stru ...
- tomcat 7 WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
tomcat 7 WARNING: A context path must either be an empty string or start with a '/' and do not end w ...
- Android 全局获取 Context 与使用 Intent 传递对象
=====================全局获取 Context======================== Android 开发中很多地方需要用到 Context,比如弹出 Toast.启动活 ...
- android开发中fragment获取context
在用到fragment时无法使用.this来指定当前context内容,android开发中fragment获取context,可以使用getActivity().getApplicationCont ...
- tomcat <context path>的意义及作用
context path 是在tomcat 要支持多个应用时对每个应用的docBase做区别时的区分符. 打个比方假如你有两个请求:一个为 http:localhost:8080/test1/hell ...
- “FAIL - Deployed application at context path but context failed to start”错误的解决
Netbeans调试错误,出现以下信息,无法启动浏览器调试. Attached JPDA debugger to localhost:tomcat_shared_memory_id 正在取消部署... ...
- Android 如何全局获取Context
有时,在处理业务逻辑的时候,需要Context对象,但在某些情况下,并非容易获取,这时就需要一些巧妙的手段来管理Context. 在Android中,提供了一个类Application,当应用程序启动 ...
随机推荐
- 再次探究Android ListView缓存机制
概述 虽然现在5.0后Google推出了RecycleView,但在5.0 Lollipop普及前Listview仍会被广泛使用,所以打算再次探究一下Listview的源码,了解一下Listview ...
- uboot总结:uboot配置和启动过程2(mkconfig分析)
说明:文件位置:在uboot的目录下,文件名为:mkconfig.本身是一个脚本文件. 它的主要作用的是: (1)创建一个重要的符号链接 (2)创建一个config.mk文件(在include目录下) ...
- CodeForces 554B(扫房间)
CodeForces 554B Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- python学习的一些感悟
首先声明,这里用到的库是在coursera上学习时,老师建立的一个库 #timer import simplegui import random # global state message = &q ...
- 用nodejs,express,ejs,mongo,extjs实现了简单了网站后台管理系统
源代码下载地址:http://download.csdn.net/detail/guoyongrong/6498611 这个系统其实是出于学习nodejs的目的而改写的系统. 原来的系统前端使用了ex ...
- hadoop各版本下载
http://hadoop.apache.org/ Download Hadoop from the release page. http://hadoop.apache.org/releases.h ...
- python Hbase Thrift pycharm 及引入包
cp -r hbase/ /usr/lib/python2.7/site-packages/ 官方示例子http://code.google.com/p/hbase-thrift/source/bro ...
- 【Java】Java6 WebService的发布
WebService服务发布往往比较混乱,Axis2的发布形式与XFire发布方式差别很大,而Java6 Web服务的发布与Axis2.XFire的Web服务的发布方式也有着天壤之别,它们之间没有经验 ...
- IE7和IE8出现的计算判断问题
吸住底部菜单 IE7和IE8下会卡死的算法 ; } function fixedBar(){ var _height=$(this).height()+$(this).scrollTop(); var ...
- 子类化窗口控件的窗口过程(系统级替换,与直接替换控件的WndProc方法不是一回事)
要说灵活性,自然是比不上Delphi自带的覆盖WndProc,或者替换WndProc方法. unit Unit1; interface uses Windows, Messages, SysUtils ...