tomcat7 and EL in a jsp page; pageContext.request.contextPath empty?

纵饮孤独 提交于 2019-12-10 15:17:26

问题


My JSP page contains:

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

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

my web.xml specifies version 2.5.


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/11580886/tomcat7-and-el-in-a-jsp-page-pagecontext-request-contextpath-empty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!