Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsp

el

tomcat7

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.

like image 270
bmargulies Avatar asked Jul 20 '12 13:07

bmargulies


1 Answers

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.

like image 108
BalusC Avatar answered Nov 01 '22 14:11

BalusC