Sue
Sue

Reputation: 125

How to display data into second column of a table in jsp by using jstl?

I would like to display a table in jsp which contains two columns (Date , Rating). Here is my jsp code:

<table id="results" ALIGN="center" BORDER="1" WIDTH="50%">
        <tr>
           <th>Date</th>
           <th>Rating</th>
        </tr>
          <c:forEach var="sDate" items="${currentSessionSelectDate}">
                <tr>
                   <td><center>${sDate}</center></td>
                </tr>
          </c:forEach>
          <c:forEach var="monthRating" items="${currentSessionMonthRating}">
                <tr>
                   <td><center>${monthRating}</center></td>
                </tr>
          </c:forEach>
</table>

"sDate" is a dataset that retrieved from database which is going to be displayed under "Date" column while "monthRating" is the dataset for "Rating" column.

How can I make the "monthRating" to be displayed under "Rating" column? Now all the data are being displayed under "Date" column. thanks if you could help.

Upvotes: 0

Views: 2409

Answers (1)

Naman
Naman

Reputation: 2203

If you are able to make one list instead of two lists than it would be better to iterate it in table. But if not possible for you than try this code may this help :)

<table border="1">
        <tr>
            <td>Date</td>
            <td>Rating</td>
        </tr>
        <tr>
            <td>

                <table>
                    <c:forEach var="sDate" items="${currentSessionSelectDate}">
                        <tr>
                            <td>${sDate}</td>
                        </tr>
                    </c:forEach>
                </table>
            </td>

            <td>
                <table>
                    <c:forEach var="monthRating" items="${currentSessionMonthRating}">
                        <tr>
                            <td>${monthRating}</td>
                        </tr>
                    </c:forEach>
                </table>

            </td>
        </tr>
    </table>

Upvotes: 1

Related Questions