pageContext.request.contextPath not working

arturopuente picture arturopuente · May 4, 2011 · Viewed 18.8k times · Source

I'm using Tomcat 6.0.32 and I'm trying to include a JSP file into another, but somehow the file cannot be found (yes, the file exists). Here is the file structure and code:

<jsp:include page="${pageContext.request.contextPath}/templates/header.jsp">
</jsp:include>

WebContent
- folder/caller.jsp
- templates/header.jsp

However, if I use ${pageContext.request.contextPath} outside of that to check if it outputs correctly, it works, does anyone know why this is happening?

Answer

matt b picture matt b · May 4, 2011

I'm not even sure if you can use runtime variables inside a <jsp:include>, but the other problem is that the contextPath refers to the context of the URL being requested from the server, and does not necessarily correspond to your filesystem layout.

Why wouldn't you just use <jsp:include page="templates/header.jsp">?