获取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,当应用程序启动 ...
随机推荐
- python之正则表达式备忘
一简介:就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C ...
- openerp binary filed import export
1: user xmlrpc 2: use csv file to export import but want to change the csv model field_size_limit
- iscc2016-basic-心灵鸡汤
用winhex打开发现 ISCCCongratulations! You need remember: DEath IS JUST A PaRT oF lIFE,sOMeTHInG wE'RE aLL ...
- MVC身份验证及权限管理
MVC自带的ActionFilter 在Asp.Net WebForm的中要做到身份认证微软为我们提供了三种方式,其中最常用的就是我们的Form认证,需要配置相应的信息.例如下面的配置信息: < ...
- 接受、online、见刊时,期刊的 IF 都不同,究竟算发几分期刊?
- myisam和innodb索引实现的不同
1.MyISAM 使用B+Tree 作为索引结构,叶子节点的data存放指针,也就是记录的地址.对于主键索引和辅助索引都是一样的.2.InnoDB 也使用B+Tree作为索引结构,也别需要注意的是,对 ...
- AOP小结
AOP主要采用代理模式来实现的,静态代理(设计模式中的代理模式),动态代理(反射机制,实现InvocationHandler接口),cglib实现(采用继承方式,针对目标类生成子类,并覆盖方法进行增强 ...
- PGA突破pga_aggregate_target限制
SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ...
- (转载)PHP去掉转义后字符串中的反斜杠\函数stripslashes
(转载)http://www.beijibear.com/index.php?aid=182 addslashes()函数主要是在字符串中添加反斜杠对特殊字符进行转义,stripslashes()则是 ...
- C#代码实现隐藏任务栏、开始菜单和禁用任务管理
一:截图,主要是调用系统接口和更改注册表实现功能 二:代码 using System; using System.Collections.Generic; using System.Linq; usi ...