我有一个 Tiles 模板,其中每个页面都提供一个标题,一些要添加到 <head>
中的内容,要放入一些混凝土的东西<div>
,以及附加到 <body>
的内容在一切之后。
大部分内容都非常小,因为页面是用 JS 呈现的。
我怎样才能去掉 tiles.xml
还是让它更易于管理?
我不希望每个页面都需要 3 个文件:
<definition name="my_page" template="/template.jsp">
<put-attribute name="title" value="My Title" />
<put-attribute name="head" value="/tiles/my-head.jsp" />
<put-attribute name="body" value="/tiles/my-page.jsp" />
<put-attribute name="body-append" value="/tiles/my-append.jsp" />
</definition>
而且我不想把所有页面的内容都放在tiles.xml中。
理想情况下,它会简单地将 my_page 重定向到 /my_page.jsp
它将自己导入和填充模板。
我说的是 TilesView
的 Spring 应用程序.
最佳答案
您可以直接在 JSP 中使用 tiles JSP 标记。如果您不想,则不必使用定义。
在您的 my_page.jsp 中:
<tiles:insertTemplate template="/template.jsp" flush="true">
<tiles:putAttribute name="title" value="My Title" />
<tiles:putAttribute name="head" value="/tiles/my-head.jsp" />
... etc
</tiles:insertTemplate>
参见 http://tiles.apache.org/framework/tiles-jsp/tlddoc/index.html
关于Spring & Tiles - 摆脱 tiles.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6825828/