JSP - All scopes are empty inside the jsp:include page

392 Views Asked by At

I want to put a variable in the requestScope so I can use it in an other page. Unfortunately, the requestScope is totally empty in this other page. In fact, when I print #{requestScope} in both pages, they don't have the same memory adresse !

mainPage.jsp

<c:set var="foo" value="${myForm.myJavaObject}" scope="request" />

<c:forEach var="scope" items="${requestScope}">
    ${scope.key} // PRINTS EVERY VARIABLE IN THE REQUEST SCOPE, INCLUDING foo
</c:forEach>

<jsp:include page="./includedPage.jsp"/>

includedPage.jsp

<c:forEach var="scope" items="${requestScope}">
    ${scope.key} // PRINTS NOTHING
</c:forEach>

Same thing if try different scopes (session, application etc.). I don't get it. This method is all over the internet, so why is it not working? First time I use it.

1

There are 1 best solutions below

0
On BEST ANSWER

It works if I include <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>. I don't get why though, as it is already included in the mainPage.jsp and because <jsp:include> is dynamic.