一直困擾着我<jsp:include..>
的事情之一是,無法將非字符串值傳遞到包含頁面作爲頁面的不同輸入。例如,我希望能夠做到以下幾點:加強jsp:包含實現
<c:forEach var="item" items="${listOfItems}">
<jsp:include page="mypage.jsp">
<jsp:attribute name="item" value="${item}/>
</jsp:include>
</c:forEach>
的想法是,通過聲明該項目正在傳遞中作爲JSP中的屬性:包括節點,代碼並明確意圖是什麼......將該參數提供給包含的頁面。
當前唯一可用的機制是定義屬性「全局」,然後讓包含的頁面從全局空間讀取它。不幸的是,這與使用< jsp:param >提供的「意圖」相同。此外,它使代碼更難以調試,因爲任何編程環境中的全局變量都會這樣做。
有沒有人知道執行jsp:include函數的include機制的實現,但是允許傳入非字符串值?或者,如果不是的話,我會接受另外的想法,以保持意圖的相同目標和易於調試。
作爲一個方面說明,我很樂意看到的,當被包含的頁面拋出一個錯誤一個內置的「捕獲」機制:
<abc:include page="mypage">
<abc:param name="something" value="some string value"/>
<abc:attribute name="somethingelse" value="${nonStringValue}"/>
<abc:catch var="ex">
The page failed, so the content it generated will not be sent to the output
stream. Instead, we can collapse the part of the page that it's content
would be... possibly putting a comment in the page with
<!-- There was an exception generating this module:
<c:out value="${ex.getMessage}/>
-->
</abc:catch>
</abc:include>
因此,我覺得自己的答案是「答案」,但我真的沒有得到我在別處尋找的東西。提供了有用的信息,但我最終不得不將它們結合在一起,並用它來開發我自己的實現。 – RHSeeger 2010-08-13 15:31:37