Reputation: 9465
I'm using spring to display a jsp page. That's fine. Now I'd like to include another page in it. I know I can use the <jsp:include>
tag in my page however I'd like to use a controller to pass some logic to the page which is to be included. Is it possible please?
Thanks,
Krt_Malta
Upvotes: 0
Views: 553
Reputation: 38290
Look into JSTL (Jsp Standard Tag Library). You can implement conditional logic in your JSP using the JSTL <c:if> or <c:choose> tags. Then, instead of splitting up the logic into multiple files and using <jsp:include> to include the logic you want, you can build all the logic into your page and the controller can set request (or other scope) attributes to turn on the logic you desire.
For example:
<c:if test="${Order66}"
<c:forEach items="${JediMembership}" var="jedi">
kill ${jedi}
</c:forEach>
</c:if>
<c:if test="${Order67}"
two large pizza, extra cheese.
</c:if>
The controller then set "Order66" and / or "Order67" in the request (or any other scope).
Upvotes: 0
Reputation: 96385
Your controller can add objects to the Model and Spring will add them to the HTTPRequest as attributes, is that what you mean? Including a jsp fragment doesn't affect that, your jsp fragment can access the request attributes. Otherwise it's unclear to me what you mean by "passing some logic to the page".
Upvotes: 1
Reputation: 13056
You might want to checkout a template engine like Freemarker or Velocity. Here's a description of how Spring integrates with view technologies.
Upvotes: 1