一、request.getContextPath()
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" perfix="c"%>
<c:set var="contPath" value="${pageContext.request.contextPath}"></c:set>
<head>
<% String contPath=request.getContextPath(); %>
</head>
二、function getContextPath()
function getContextPath(){
var pathName=document.location.pathname;
var index=pathName.substr(1).indexOf("/");
var result=pathName.substr(0,index+1);
return result;
}
var contPath=getContextPath();
三、赋值一个hidden的控件
<input type=“hidden” name=“contextPath” value=<%= request.getContextPath() %> >
然后js里面获取hidden 的值