728x90
반응형
728x90
반응형

자바스크립트에서 Contextpath 가져오는 함수에 대해 알아보려고 합니다.

먼저 ContextPath란 http://127.0.0.1:80/animal/login.jsp라는 url에서 

animal이 ContextPath를 의미합니다.

 

아래 함수를 사용하시면 ContextPath를 값을 가져오실 수 있습니다.

function getContextPath() {
    var hostIndex = location.href.indexOf( location.host ) + location.host.length;
    return location.href.substring( hostIndex, location.href.indexOf('/', hostIndex + 1) );
}

728x90
반응형
728x90
반응형

+ Recent posts