gpt4 book ai didi

java - 以表格格式在jsp中显示来自servlet的arraylist值

转载 作者:行者123 更新时间:2023-11-29 08:21:27 25 4
gpt4 key购买 nike

<分区>

我试图在从数据库获取后在 jsp 中的表中显示学生数据

学生 Servlet

ArrayList student = new ArrayList();
String selectSQL = "SELECT studentname from student";

while (rs.next()) {
studentname = rs.getString(1);
student.add(studentname);
}

request.setAttribute("student", student);
request.getRequestDispatcher("home.jsp").include(request, response);

home.jsp

<%
ArrayList List = new ArrayList();
String student = (String) request.getAttribute("student");
List.add(student);

Iterator<String> itr = List.iterator();
while (itr.hasNext()) {
%>

<table>
<tr>
<th>Students</th>
</tr>
<tr>
<td><%=itr%>
</td>
</tr>
</table>

<%
}
%>

home.jsp 部分有问题。非常感谢任何帮助。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com