jsp页面中的tomcat7和EL; pageContext.request.contextPath为空? [英] tomcat7 and EL in a jsp page; pageContext.request.contextPath empty?

查看:70
本文介绍了jsp页面中的tomcat7和EL; pageContext.request.contextPath为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSP页面包含:

<script>
    var bt_wd40_appurl = "${pageContext.request.contextPath}";
</script>

视图/源显示为值的".到目前为止,我还没有发现错误.

view/source shows "" for the value. No errors I've found so far.

我的web.xml指定版本2.5.

my web.xml specifies version 2.5.

推荐答案

如果将Webapp部署在ROOT上,它将为空.另请参见其 javadoc (强调我的):

It will be empty if you deployed the webapp on ROOT. See also its javadoc (emphasis mine):

getContextPath

java.lang.String getContextPath()

返回请求URI中指示请求上下文的部分.上下文路径总是在请求URI中排在第一位.路径以"/"字符开头,但不以"/"字符结尾. 对于默认(根)上下文中的servlet,此方法返回".容器不对该字符串进行解码.

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.

确定要 did 将其部署在上下文路径中吗?请注意,上下文路径不包含URL的scheme/domain部分,它是相对于域的URL.

Are you sure that you did deploy it on a context path? Note that the context path doesn't contain the scheme/domain part of the URL, it's a domain-relative URL.

这篇关于jsp页面中的tomcat7和EL; pageContext.request.contextPath为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆