我想将一个 JSP 页面包含到另一个 JSP 页面中。假设我有 master.jsp
这包括 slave.jsp
.
如 slave.jsp
有自己的<head>
处理 JavaScript 和 CSS 的部分,有没有办法或另一种方法来合并 master
和 slave
头 s 部分变成一个?对 也应该这样做车身 s 节。
我一直在用网站网最近,但我认为为每个页面设置模板是非常不切实际的。
最佳答案
我通过传递 来寻求这个解决方案参数 包含页面时。
在 master.jsp
<head>
blablabla
<c:import url="slave.jsp">
<c:param name="sectionName" value="HEAD" />
</c:import>
</head>
<body>
blablabla
<c:import url="slave.jsp">
</c:import>
</body>
然后在 slave.jsp 读取参数并呈现页面的自定义部分。
<c:choose>
<c:when test="${param.sectionName == 'HEAD'}">
head section here [without the <HEAD> tags !]
</c:when>
<c:otherwise>
body section here [without the <BODY> tags !]
</c:otherwise>
</c:choose>
不太好看到但工作。通过这种方式,我可以删除
HEAD
的重复项和 BODY
部分。
关于jsp - 将 JSP 页面包含到另一个 JSP 页面中,如何避免多个 HEAD/BODY 部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1841274/