<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>ListDeveloper</title> </head> <body> <table> <colgroup> <col span="2" style="background:Khaki"><!-- С помощью этой конструкции задаем цвет фона для первых двух столбцов таблицы--> <col style="background-color:#ff564f"> <col style="background-color:#33d1ff"> <col style="background-color:#2cff23"> <col style="background-color:#d94cff"> </colgroup> <tr> <th >ID</th> <th >FIRST_NAME</td> <th >LAST_NAME</td> <th>SPECIALTY</td> <th>SKILLS</td> <th>ACCOUNTS</td> </tr> <tr> <c:forEach items="${temp}" var="d" > <td>${d.id}</td> <td>${d.firstName}</td> <td>${d.lastName}</td> <td>${d.specialty}</td> <c:forEach items="${d.skills}" var="trt"> <td>${trt.name}</td><br> </c:forEach> <td>${d.account.accountData}</td> </c:forEach> </tr> </table> </body> </html> 

Problems with the output of the table the second object is not displayed with a new line, the br tag does not help enter image description here

  • Put tr inside forEach - andreymal pm

2 answers 2

You only need to place the tr tag in the middle of the forEach loop to preserve the structure of the table.

 <c:forEach items="${temp}" var="d" > <tr> <td>${d.id}</td> <td>${d.firstName}</td> <td>${d.lastName}</td> <td>${d.specialty}</td> <c:forEach items="${d.skills}" var="trt"> <td>${trt.name}</td><br> </c:forEach> <td>${d.account.accountData}</td> </tr> </c:forEach> 

    tr in forEach place. It can be seen that you do not have this element in the loop, therefore, within the framework of the same tr, you add the second element, “breaking” the table structure.

    • need to rest a bit)) thanks - Alexandr Denisenko