I’ve got a simple .jsp file using <c:import url=”…jsp”> for header and footer.
For the header it works great: there’s some ${…} EL substitution being done inside the header.jsp that I c:import and every time the user reloads the page everything is fine and well.
However in the footer there’s something I don’t get: I tried to put some JSTL inside my footer.jsp but it doesn’t work.
Instead of evaluating the JSTL the tags in my footer.jsp are served to the browser.
For example, if I ask to view the page source code from Chrome I see:
<div>
<c:if test="false">
...
</c:if>
</div>
The header.jsp and footer.jsp are both imported using c:import. How comes EL substitution works but JSTL tags do not?
If I need to “include” instead of “import”, then I’ve got two questions:
-
can I “include” using JSTL and if so how?
-
how comes EL substitution is still taking place when I do a c:import while JSTL tag do not work?
You should indeed use
<%@ include file="footer.jsp" %>– then all EL will be resolved (same goes for header)<c:import />evaluates the target resource and then includes it in the page. If your footer does not declare EL expression parsing properly (in older versions of JSP it is not on by default), then the included result would contain<c:tags.