我是第一次使用瓷砖。试图在我的 Spring MVC 项目中布局我的 JSP 页面。
请看看我在做什么,让我知道这是否是“正确”的方法……我的具体问题在底部……
我有这样结构的文件......文件夹/src/main/webapp/WEB-INF/layouts/
包含......
标准.jsp
// ...
<html>
<title><tiles:insertAttribute name="title"/></title>
// ... LOTS OF HTML ...
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="body"/>
<tiles:insertAttribute name="footer"/>
// ... LOTS OF HTML
</html>
// ...
瓷砖.xml
<tiles-definitions>
<definition name="standardLayout" template="/WEB-INF/layouts/standard.jsp">
<put-attribute name="title" value="My Directory" />
<put-attribute name="header" value="/WEB-INF/layouts/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="" />
</definition>
</tiles-definitions>
我的可见 JSP 位于文件夹中/src/main/webapp/WEB-INF/views/
,其中包含...
瓷砖.xml
<tiles-definitions>
<definition name="home" extends="standardLayout">
</definition>
</tiles-definitions>
主页.jsp
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<tiles:insertDefinition name="home">
<tiles:putAttribute name = "body" value="/WEB-INF/views/home-body.jsp"/>
</tiles:insertDefinition>
主页body.jsp
<div>
// LOTS OF HTML FOR THE BODY OF THE HOME PAGE
</div>
问题:我只想拥有一个,home.jsp
但看起来我必须从一个单独的文件中提取正文内容(和任何其他内容)。是否有适当的方法来简化home.jsp
并home-body.jsp
合并到一个文件中,或者我实际上是否正确地做到了这一点?
你需要更新你的tiles.xml、standard.jsp和home.jsp,如下所示,
瓷砖.xml
<tiles-definitions>
<definition name="home" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/views/home.jsp"></put-attribute>
</definition>
</tiles-definitions>
标准.jsp
<html>
<title><tiles:insertAttribute name="title"/></title>
<header>
<tiles:insertAttribute name="header"/>
</header>
<body>
<tiles:insertAttribute name="body"/>
</body>
<footer>
<tiles:insertAttribute name="footer"/>
</footer>
</html>
主页.jsp
<!-- Actual body content goes here.. -->
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<p>The content of the home page.</p>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句