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);
    }
  • 相关阅读:
    053467
    053466
    053465
    NC201613 Jelly
    NC14608 after与迷宫
    NC14572 走出迷宫
    340. 通信线路
    1135. 新年好
    903. 昂贵的聘礼
    P5767 [NOI1997]最优乘车
  • 原文地址:https://www.cnblogs.com/luyang1990/p/4730552.html
Copyright © 2011-2022 走看看