gpt4 book ai didi

java - Spring Java中使用一个 Controller 调用2个或多个 View

转载 作者:行者123 更新时间:2023-12-02 08:38:05 26 4
gpt4 key购买 nike

我想在 Spring 中使用 java 调用一个 Controller 中的 2 个 View 。例如

this.controller.view('header');
this.controller.view('body');
this.controller.view('footer');

我该怎么做?或者 Spring 有可能吗?或者你能建议任何其他方法吗?

我可以在 View 内调用 View 吗?例如在 view/login.jsp 中,

<table><tr><td>
<jsp>this.controller.view('login_form')</jsp>
</td></tr></table>

是的,我在那里编写的所有代码都不是有效的 jsp 语言,但这就是我想在这个项目中实现的概念。

最佳答案

您似乎希望在多个 JSP 页面中重用 JSP 片段(页眉、页脚)。如果是这种情况,请考虑使用一个专用 View (例如 login_form.jsp)并使用 JSP include合并该 JSP 页面中“公共(public)”片段的语句。

作为示例(login_form.jsp):

<jsp:include page="header.jsp"/>
<!-- login_form specific page content goes here -->

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

这将允许您在多个 JSP 页面中重用公共(public)页眉和页脚内容。

我还建议查看 Spring MVC ( documentation ),对于基于 Spring 的 Web 应用程序来说,这是一个非常好的方法。

关于java - Spring Java中使用一个 Controller 调用2个或多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/801446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com