如何使用spring控制器从JavaScript获取pagecontextPath.request.contextpath?

时间:2015-12-23 11:55:58

标签: javascript jsp spring-mvc

window.location.href=location.origin+"/apreizspring/teammember"

apreizspring是我的项目名称。我想使用pagecontext替换它。任何人都可以为我提供解决方案吗?

1 个答案:

答案 0 :(得分:3)

在Javascript文件中:

window.location.href = requestContextPath + "/teammember"

可以说,您的javascript文件名为temp.js

在jsp中:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<script>
    var requestContextPath = '${pageContext.request.contextPath}';
</script>
<script type='text/javascript' src = 'temp.js'></script>