Jsp 在ApacheTiles中处理静态资源
我使用的是apache tiles3,我有一个带有默认空属性的经典布局:Jsp 在ApacheTiles中处理静态资源,jsp,model-view-controller,apache-tiles,Jsp,Model View Controller,Apache Tiles,我使用的是apache tiles3,我有一个带有默认空属性的经典布局: <definition name="t-empty" template="/WEB-INF/tiles/template/empty.jsp"/> //the base template is the site, <definition name="base" template="/WEB-INF/tiles/layout/classic.jsp"> <put-attribute n
<definition name="t-empty" template="/WEB-INF/tiles/template/empty.jsp"/>
//the base template is the site,
<definition name="base" template="/WEB-INF/tiles/layout/classic.jsp">
<put-attribute name="res" value="t-empty"/>
<put-attribute name="header" value="t-empty"/>
<put-attribute name="body" value="t-empty"/>
<put-attribute name="footer" value="t-empty"/>
</definition>
然后,对于conrete页面,我将放置所有必需的属性,以及它自己的资源(如果有):
<definition name="user-list-page" extends="single-page-bb">
<put-attribute name="header" value="/WEB-INF/tiles/fragment/user-list.jsp"/>
<put-list-attribute name="res" inherit="true">
<add-attribute value="/WEB-INF/tiles/fragment/user-list-res.jsp"/>
</put-list-attribute>
</definition>
它可以工作,但我发现这很不方便,因为我必须将用户列表
页面的资源放在页面之外
我想知道是否可以将资源放在互动程序用户列表中
如果我理解正确,问题的核心是put list属性值被视为字符串。这意味着,我们不能使用tiles:insertAttribute标记。我在顶部使用了tiles:importAttribute,然后通过c标记和表达式语言(el)在列表中循环
也看到
baseLayout.jsp
注意c:forEach中的链接和脚本标记
No,因为“header”是在classic.jsp和每个“res”页面之后呈现的。那么如果我们需要在head
标记中添加一些内联资源,您如何处理这种用例?必须在呈现header属性之前定义它。这通常发生在控制器层,或者通过合成header属性,而不是依赖于重新使用res页面的合成。(例如,您可以在标题合成中构建“res”列表,以避免双属性列表的复杂性)
<definition name="user-list-page" extends="single-page-bb">
<put-attribute name="header" value="/WEB-INF/tiles/fragment/user-list.jsp"/>
<put-list-attribute name="res" inherit="true">
<add-attribute value="/WEB-INF/tiles/fragment/user-list-res.jsp"/>
</put-list-attribute>
</definition>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="tilesx" uri="http://tiles.apache.org/tags-tiles-extras" %>
<tiles:importAttribute name="styles" />
<tiles:importAttribute name="scripts" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
<title><tiles:getAsString name="title" /></title>
<c:forEach items="${styles}" var="style" >
<link rel="stylesheet" type="text/css" href="<c:url value='${style}' />" />
</c:forEach>
</head>
<body>
<header id="header">
<tiles:insertAttribute name="header" />
</header>
<section id="body">
<tiles:insertAttribute name="body" />
</section>
<footer id="footer">
<tiles:insertAttribute name="footer" />
</footer>
<c:forEach items="${scripts}" var="script" >
<script src="<c:url value="${script}"/>"></script>
</c:forEach>
</body>
</html>