zoukankan      html  css  js  c++  java
  • java 或者 js 获取项目访问路径(域名)

    /**
     * 获得站点url
     * @return
     */
    public String getWebUrl(){
      String url = getRequest().getScheme() + "://" + getRequest().getServerName();
      if(getRequest().getServerPort()!=80){
        url+= ":" + getRequest().getServerPort();
      }
      url+=getRequest().getContextPath();
      return url;
    }

    js

    /**
     * 获取项目跟路径,http://localhost:8080/userCenter
     * @returns
     */
    function getContextPath() {
       //获取当前网址,如: 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);
    }
  • 相关阅读:
    第六章 函数与宏定义实验
    第五章 循环结构实验
    第五章 循环结构课内反思
    第四章 分支结构实验
    C程序设计实验报告
    509寝室小组
    第九章 构造数据类型实验
    第八次实验报告
    数组实验
    函数与宏定义实验
  • 原文地址:https://www.cnblogs.com/luyang1990/p/4730552.html
Copyright © 2011-2022 走看看