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

1

5

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.

Lungan answered 20/7, 2012 at 13:58 Comment(2)
It will be empty if you deployed the webapp on ROOT. 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.Freethinker
Oh, duh! IDEA did exactly that. Make an answer so I can accept?Lungan
F
10

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.

Freethinker answered 20/7, 2012 at 14:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.