gpt4 book ai didi

java - 如何用jsp和servlet创建模板

转载 作者:行者123 更新时间:2023-11-30 09:04:36 26 4
gpt4 key购买 nike

假设我有一个包含 10 个页面的网站。每个页面都由一个 servlet 调用。例如,我有一个 servlet“index”,它将 forward() 转换为“index.jsp”。

在我的 index.jsp 中,我有 2 个包含页眉和页脚

...
<jsp:include page="header.jsp" >
home page text
<jsp:include page="footer.jsp" >
...

现在我有 10 个类似于索引页的页面,我的意思是我有 10 个包含页眉和页脚的页面。

假设我决定删除页脚:我应该编辑 10 页。

我想知道是否有什么东西可以让我只使用一个页面,并动态地显示页面的“内容”(主页、联系人、ecc),请记住我使用 servlet 来获取每个页面内容(使用 forward())。

最佳答案

你需要的是Apache Tiles Framework ,

Tiles allows authors to define page fragments which can be assembled into a complete pages at runtime. These fragments, or tiles, can be used as simple includes in order to reduce the duplication of common page elements or embedded within other tiles to develop a series of reusable templates. These templates streamline the development of a consistent look and feel across an entire application.

它包含配置文件,因此您可以单独在一个文件中进行编辑,这样更改将反射(reflect)在所有 jsp 文件中。

一个不错的Startup tutorial这里

关于java - 如何用jsp和servlet创建模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25161586/

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