jsp - jsp页面中的tomcat7和EL; pageContext.request.contextPath 为空?

标签 jsp el tomcat7

我的 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/

相关文章:

java - jsp中的sql查询放在哪里

java - 如何将字符串从一个jsp传递到另一个jsp,其中每个字符串都在链接中,并通过单击链接方式检索字符串

eclipse - JSP EL(表达语言)在Eclipse中引起问题

tomcat - 如何在 Tomcat 7 上重新启用已删除的虚拟主机管理器?

java - Tomcat 7.1 为来自同一客户端的每个请求创建新 session

java - 如何将 'null' 值插入 blob 字段 (mysql)

java - 为什么我收到 JasperException PWC :6299 for a custom jsp EL function?

java - JSP隐式对象和EL表达式隐式对象有什么区别?

java - ExpressionLanguage (EL) 未按预期工作

java - Controller 与 url 不匹配