您的位置:首页 > 运维架构 > 网站架构

获取网站根目录contPath

2018-02-23 10:08 239 查看
一、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 的值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  contPath