我的 JSP 页面包含:
<script>
var bt_wd40_appurl = "${pageContext.request.contextPath}";
</script>
View /源显示“”作为值。到目前为止我没有发现任何错误。
我的 web.xml 指定版本 2.5。
最佳答案
如果您在 ROOT 上部署了 webapp,它将为空。另见其 javadoc (强调我的):
getContextPath
java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.
您确定您确实在上下文路径上部署了它吗?请注意,上下文路径不包含 URL 的方案/域部分,它是域相对 URL。
关于jsp - jsp页面中的tomcat7和EL; pageContext.request.contextPath 为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11580886/