2

我在我的网络应用程序中使用 Tiles。我在瓷砖中有一个标准布局(standard.jsp)。在standard.jsp 之上有很多包含,涉及标签库等。

让我们做一个简化的例子。

标准.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/includes/include.jsp" %>

<html>

<head>
    <tiles:insertAttribute name="head" flush="false"/>
</head>

<body>
    <tiles:insertAttribute name="body" flush="false"/>
</body>    

</html>

身体.jsp:

<div id="body-div">
    <p>Hello, <c:out value="${forname}" />!</p>
</div>

这打印:

Hello, !

在瓷砖中,我想使用标签,但它不起作用。仅当我将包含添加到 tile-jsp 时,它才有效。

body.jsp 包括:

<%@ include file="/WEB-INF/jsp/includes/include.jsp" %>

<div id="body-div">
    <p>Hello, <c:out value="${forname}" />!</p>
</div>

这打印:

Hello, John!

有没有更好的方法来做到这一点,或者我必须将所有包含添加到每个使用的 jsp 中?

4

1 回答 1

1

您不需要所有包含都存在于每个磁贴中,但磁贴中的每个使用的标签库都必须明确包含在使用磁贴中。

例如:在您的示例中,使用 C JSTL 库的每个图块至少应<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>包含包含

于 2009-02-11T09:47:00.047 回答