jsでbasePathを取得します


/**
 * Created by Administrator on 2015/10/31.
 * 
 *     jsp    ,          url   
 * 
 *     ,     jQuery        
 * 
 *          ,   ready         ,  basePath
 */


 function basePath(){
    //      , : http://localhost:8080/ems/Pages/Basic/Person.jsp
    var curWwwPath = window.document.location.href;
    //           , : /ems/Pages/Basic/Person.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //      , : http://localhost:8080
    var localhostPath = curWwwPath.substring(0, pos);
    //   "/"    , :/ems
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    //     basePath   http://localhost:8080/ems/
    var basePath=localhostPath+projectName+"/";
    return basePath;
};
//    
var basePath;;

$(document).ready(
        function() {
            basePath=basePath();
            alert(basePath);
//    
//http://127.1.0.1:8088/xuchang_lvyou/
 });