2013-07-21 20 views
0

我在jsp頁面內部有html表格。我的代碼如下所示:如何在jsp頁面的html表格中重複使用相同的<tr>標記

<c:choose>  
    <c:when test="${empty institutionAttributes}">  
     <h2 align="center"><spring:message code="label.attributes.msg"/> </h2>  
    </c:when> 

    <c:otherwise> 
     <h3 align="center"><spring:message code="label.result.msg"/> </h3>  
     <table border="1" align="center">    
     <thead> 
      <tr> 
       <th align="center"><spring:message code="label.header.table.name" /></th> 
       <th align="center"><spring:message code="label.header.table.type" /></th> 
       <th align="center"><spring:message code="label.header.table.date" /></th> 
       <th align="center"><spring:message code="label.header.table.dayscheduale" /></th> 
       <th align="center"><spring:message code="label.header.table.workscheduale" /></th> 
       <th align="center"><spring:message code="label.header.table.rotation" /></th> 
       <th align="center"><spring:message code="label.header.table.numberkids" /></th> 
       <th align="center"><spring:message code="label.header.table.under3" /></th> 
       <th align="center"><spring:message code="label.header.table.upper3" /></th> 
       <th align="center"><spring:message code="label.header.table.goschool" /> <br> <fmt:formatDate value="${formDescriptionVar.kidsGoSchoolDate}" pattern="yyyy"/> <spring:message code="label.header.table.year" /></th> 
      </tr> 
     </thead> 

     <tbody>     
      <c:forEach items="${institutionAttributes}" var="institutionVar"> 
       <tr> 
        <td align="center">${institutionVar.nameOfInstitution}</td> 
       </tr> 
      </c:forEach> 

      <c:forEach items="${institutionTypeAttributes}" var="institutionTypeVar"> 
       <tr> 
        <td align="center">${institutionTypeVar.typeOfInstitution}</td> 
       </tr> 
      </c:forEach> 

      <c:forEach items="${formDateAttributes}" var="formDateVar"> 
       <tr> 
        <td align="center"><fmt:formatDate value="${formDateVar.particularDate}" pattern="dd-MM-yyyy"/> </td> 
       </tr> 
      </c:forEach> 

      <c:forEach items="${formDescriptionAttributes}" var="formDescriptionVar"> 
       <tr> 
        <td align="center">${formDescriptionVar.daySchedule}</td> 
        <td align="center">${formDescriptionVar.workScheduale}</td> 
        <td align="center">${formDescriptionVar.rotation}</td> 
        <td align="center">${formDescriptionVar.numberOfKids}</td> 
        <td align="center">${formDescriptionVar.kidsUnder3YearsOld}</td> 
        <td align="center">${formDescriptionVar.kidsUpper3YearsOld}</td> 
        <td align="center">${formDescriptionVar.kidsGoSchoolNumber}</td>    
       </tr> 
      </c:forEach> 
      </tr>   

     </tbody> 

     </table> 
    </c:otherwise> 
</c:choose> 

內JSP頁面中我有<thead><tbody>標籤表。

<tbody>我使用JSP的<c:forEach>標籤。

<c:forEach>我使用<tr><td>標籤。

在照片,我想:

|------------------------------------| 
| Header1 | Header2 | Header3 | 
|------------------------------------| 
| Value1 | Value2 | Value3 | 
|------------------------------------| 

我能得到什麼:

|------------------------------------| 
| Header1 | Header2 | Header3 | 
|------------------------------------| 
| Value1 |   |   | 
|------------------------------------| 
|   | Value2 |   | 
|------------------------------------| 
|   |   | Value3 | 
|------------------------------------| 

那麼,問題是,<c:forEach>創造新<tr><c:forEach>裏面,但我需要的是使用相同<tr>不同<c:forEach>。我怎樣才能做到這一點?

回答

0

或者我沒有正確理解你的問題,或者你的問題有一個非常簡單的解決方案。

你只需把<tr>標籤forEach之外,例如:

<tr> 
    <c:forEach items="${institutionAttributes}" var="institutionVar"> 
    <td align="center">${institutionVar.nameOfInstitution}</td> 
    </c:forEach> 
</tr> 

這將在表中創建只有1列,其中在institutionAttributes每個值1列...

一旦foreach被處理,你的HTML看起來像:

<tr> 
    <td align="center">nameOfInstitution1</td> 
    <td align="center">nameOfInstitution2</td> 
    <td align="center">nameOfInstitution3</td> 
    ... 
</tr> 
+0

是的,我很抱歉,我的問題是不夠清楚..我編輯它 –

+0

@ user2547487,我仍然認爲你需要做的是我解釋的......你試過了嗎? – MikO

+0

先生。它會在每一行中放置1,2,3的名稱,將其劃分爲新的一行。我不希望它是這樣的。我需要將nameofInstitution1和nameofInstitution2和nameofInstitution3放在一行中。就像在我上面的圖片中,我想要的... –

相關問題