Issue
I am trying to create a dynamic table within .jsp
. I have been attempting to do so through scriptlets in the following way (this is pseudocode):
<%
PrintWriter writer = response.getWriter();
writer.println("<table>");
while(records in request object){
writer.println("<tr>" + request.getAttribute().toString() + "</tr>");
}
writer.println("</table");
writer.close();
%>
While the above method can and does work, it is both discouraged, and probably not the best way of accomplishing this task.
To my point and question - is there a better way to create such dynamic content?
Solution
It can be done without scriptlets:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:if test="${not empty request.records}">
<table>
<c:forEach items="${request.records}" var="record">
<tr><td> ${record} </td></tr>
</c:forEach>
</table>
</c:if>
Answered By - Krystian G