2016-11-09 83 views
1

我有一些輸入的表單;每個輸入都會返回在另一個html頁面的表格中顯示的數據列表。每個輸入都有一個表來顯示它的數據。我的任務是如果輸入不是由用戶輸入,則不顯示數據。java:根據條件隱藏或顯示錶格

這裏是我的代碼

<!-- Country Table--> 
        <%for(int i = 0; i < countryList.length;i++){ 
         if(countryList.length == 0) 

          break; 
         %> 
        <div class="box" align="center"> 
         <table name="tab" align="center" class="gridtable"> 
          <thead > 
           <tr> 
            <th style="width: 50%" scope="col">Entity Watch List Key</th> 
            <th style="width: 50%" scope="col">Watch List Name</th> 
           </tr> 
          </thead> 
          <tbody> 

           <tr> 
           <td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td> 
           <td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td> 
           </tr> 


          </tbody> 
         </table> 
        </div> 
         <%}%> 

我使用突破走出循環做不顯示錶,是真的嗎?

回答

0

你可以前的for循環使用這個條件,

if(countryList.length != 0) 

if(countryList.length > 0) 

,然後你還需要使用斷點條件,

此外for循環你當前定義將無法正常工作,因爲如果數組的長度爲0,那麼這個條件我將會變爲0 < 0並且它將會我失敗了,所以你的for循環甚至不會被輸入。所以你的當前條件if(countryList.length == 0)將不會被訪問。

0

請修改代碼

<div class="box" align="center"> 
<table name="tab" align="center" class="gridtable"> 
    <thead > 
     <tr> 
      <th style="width: 50%" scope="col">Entity Watch List Key</th> 
      <th style="width: 50%" scope="col">Watch List Name</th> 
     </tr> 
    </thead> 
    <tbody> 

<%for(int i = 0; i < countryList.length;i++){ 
     if(countryList.length > 0) %> 
      <tr> 
      <td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td> 
      <td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td> 
      </tr> 

<%}%> 
    </tbody> 
</table> 
</div> 

對於必須重複的行不是表一個很好的做法。

相關問題