我正在尝试在 .jsp
中创建动态表。我一直在尝试通过 scriptlet 按以下方式执行此操作(这是伪代码):
<%
PrintWriter writer = response.getWriter();
writer.println("<table>");
while(records in request object){
writer.println("<tr>" + request.getAttribute().toString() + "</tr>");
}
writer.println("</table");
writer.close();
%>
虽然上述方法可以并且确实有效,但它既不鼓励,也可能不是完成此任务的最佳方法。
就我的观点和问题而言 - 是否有更好的方法来创建此类动态内容?
最佳答案
无需 scriptlet 即可完成:
<%@ 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>
关于java - .jsp动态表创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57261157/