2010-12-22 97 views
0
<c:if test="${not empty userList)}"> 
    <table cellpadding="5"> 
     <tr class="even"> 
      <th>Name</th> 
      <th>Gender</th> 
      <th>Country</th> 
      <th>About You</th> 
     </tr> 
     <c:forEach items="${userList}" var="user" varStatus="status"> 
      <tr class="<c:if test="${status.count % 2 == 0}">even</c:if>"> 
       <td>${user.name}</td> 
       <td>${user.gender}</td> 
       <td>${user.country}</td> 
       <td>${user.aboutYou}</td> 
      </tr> 
     </c:forEach> 
    </table> 
</c:if> 

當我刪除<c:if test="${not empty userList)}"></c:if>它會引發錯誤。 這個條件檢查什麼?我的數據庫表有用戶列表,但是這整個代碼不會顯示在我的HTML本身中。這種情況有什麼作用?

+1

爲什麼這個標記的Java? – 2010-12-22 08:29:16

回答

3

該行相當於

if(userList!=null && userList.size()>0) 
0

它檢查如果列表中包含的數據,如果這樣,可以使用在foreach。如果您在空列表或空列表上使用foreach,它將引發異常。

0

當我刪除<c:if test="${not empty userList)}"></c:if>它會引發錯誤。

讓我感到驚訝。我希望它是其他方式。我希望在刪除該行時該錯誤消失。它的語法無效。以下句法有效:

<c:if test="${not empty userList}"> 

在將來的問題中,請發佈確切的錯誤消息和跟蹤。他們講述了有關問題的原因。你知道,一旦某個問題的原因是理解爲,那麼該解決方案就會說明問題。

相關問題