[英]How to avoid redeclaring tag libraries in included JSP files?
我為自己的Web應用程序中的所有JSP創建了模板,使事情變得非常簡單:
<%@ include file="header.jsp" %>
<!-- Put unique content here -->
<%@ include file="footer.jsp" %>
我決定將導航菜單從header.jsp移到它自己的文件中,因為它越來越大。 我將菜單的代碼放入menu.jsp中。 這是include在我的header.jsp內部的外觀:
<html>
<head>
<title>My JSP</title>
</head>
<body>
<jsp:include page = "menu.jsp"/>
......
但是,除非我也將以下行放入其中,否則menu.jsp將無法工作:
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
那已經在我的header.jsp中。 我只想把它放在那里。 但是,當我嘗試使用此語法代替時:
<%@ include file="menu.jsp" %>
我從WebLogic 11g中收到一條錯誤消息,指出
<%@ include file="header.jsp" %> is self refrencing
我如何在header.jsp中包含menu.jsp,而不必在menu.jsp中包含JSTL?
如果動態使用的JSP頁面( <jsp:include />
)使用taglib,則它必須具有taglib聲明,因為它是單獨編譯的。
靜態包含的JSP頁面沒有相同的限制,因為它被編譯到servlet本身中。
在使用它的JSP中聲明標簽庫有什么大不了的? 這使它成為獨立的功能“塊”,可以動態地包含在任何地方,可以自我記錄,而不必擔心頁面所包含的頁面:這是功能分解的目標。
也許改為使用指令<%@ include file="page" %>
其中包括頁面的源代碼),嘗試使用標准操作<jsp:include page="page"/>
或JSTL <c:import url="page"/>
,其中包括頁面的動態響應,而不是其代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.