开发者

Including a page using spring

开发者 https://www.devze.com 2023-02-01 20:53 出处:网络
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 pas

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?

Thank开发者_如何学Pythons,

Krt_Malta


You might want to checkout a template engine like Freemarker or Velocity. Here's a description of how Spring integrates with view technologies.


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".


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号