Senith Umesha
Senith Umesha

Reputation: 164

Show a List of value vertically in jsp page

<table class="table">
                <thead>
                    <tr>
                        <th scope="col">Book Id</th>
                        <th scope="col">Book Name</th>
                        <th scope="col">Book Author</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><c:forEach items="${searchedBook}" var="book">
                            ${book.book_id}
                        </c:forEach></td>
                    </tr>
                    <tr>
                        <td><c:forEach items="${searchedBook}" var="book">
                            ${book.book_name}
                        </c:forEach></td>
                    </tr>
                    <tr>
                        <td><c:forEach items="${searchedBook}" var="book">
                            ${book.book_author}
                        </c:forEach></td>
                    </tr>
                </tbody>
            </table>

how the table looks like now

but how I want it is like this, the way I want it to look like

Is there a way to make it possible?

Upvotes: 1

Views: 148

Answers (1)

Faheem azaz Bhanej
Faheem azaz Bhanej

Reputation: 2396

You declare forEach loop inside <td> tag it print all data in single <td>

Here down modified code:

<table class="table">
 <thead>
  <tr>
    <th scope="col">Book Id</th>
    <th scope="col">Book Name</th>
    <th scope="col">Book Author</th>
</tr>
</thead>
<tbody>
    <tr>
        <c:forEach items="${searchedBook}" var="book">
        <td>${book.book_id}</td>
        </c:forEach>
    </tr>
    <tr>
        <c:forEach items="${searchedBook}" var="book">
        <td>${book.book_name}</td>
        </c:forEach>
    </tr>
    <tr>
        <c:forEach items="${searchedBook}" var="book">
        <td>${book.book_author}</td>
        </c:forEach>
    </tr>
</tbody>
</table>

Upvotes: 1

Related Questions