2012-07-23 16 views
1

我在JSPX文件中寫入這樣的代碼,奇怪JSPX問題<c:if>

<table> 
    <c:forEach var="var" items="${items}" varStatus="status"> 

    <c:if test="${(status.index) % 4 == 0}"> 
     <tr> 
    </c:if> 

    <td>some contents</td> 

    <c:if test="${(status.index+1) % 4 == 0 || status.last}"> 
     </tr> 
    </c:if> 

    </c:forEach> 
</table> 

的問題是,在<tr></tr>會導致JSPX編譯錯誤。它會說「<tr>應以</tr>結束」。但是,對於JSP來說很好。

有沒有辦法在JSPX中做這樣的事情?謝謝!

回答

0

我想你可以做到以下幾點:

<table> 
    <c:forEach var="var" items="${items}" varStatus="status"> 

    <c:if test="${(status.index) % 4 == 0}"> 
     <c:out value="&lt;tr&gt;" escapeXml="false"/> 
    </c:if> 

    <td>some contents</td> 

    <c:if test="${(status.index+1) % 4 == 0 || status.last}"> 
     <c:out value="&lt;/tr&gt;" escapeXml="false"/> 
    </c:if> 

    </c:forEach> 
</table> 
+0

謝謝!有用。據說JSPX在文檔無誤且格式正確之前不會評估EL。但是它通常在JSPX中使用嗎?那真是醜陋... – 2012-07-23 14:21:21