我嘗試創建一個jsp標記文件,它將調用幫助器類來打印輸入對象。所以,我創建了一個文件/WEB-INF/tags/formatter.tag在循環內部的jsp標籤文件中訪問變量?
<%@ tag import="package.Formatter"%>
<%@ attribute name="value" required="true" type="java.lang.Object" %>
<%=Formatter.format(pageContext.getAttribute("value"))%>
所以,我可以把它在JSP這樣的:
<t:formatter value="${obj}" />
但是我發現,它不會在一個循環內工作,例如
<c:forEach items="${list}" var="i">
<t:formatter value="${i.property}"/>
</c:forEach>
我懷疑我不應該從pageContext
獲取屬性。但我不確定。任何人都知道這件事?
「不工作」是什麼意思?你得到一個錯誤或錯誤的結果? – moxn 2009-10-10 06:11:48
websphere得到了一些ArrayIndexOutOfBoundException,引發com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.getELExpressions – jackysee 2009-10-12 01:45:06