Home > Software design >  Show a List of value vertically in jsp page
Show a List of value vertically in jsp page

Time:09-17

<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?

CodePudding user response:

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>
  • Related