zoukankan      html  css  js  c++  java
  • 获取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;

    两种实现的方法用在不同的环境中。

    梦想还是要有的,万一实现了呢!
  • 相关阅读:
    表连接问题
    public interface Serializable?标记/标签接口
    4.21
    第十周周记
    测试
    第九周周记
    第七周周记
    fighting.
    fighting
    作业一
  • 原文地址:https://www.cnblogs.com/jianfeijiang/p/6098935.html
Copyright © 2011-2022 走看看