【发布时间】:2017-08-31 00:39:04
【问题描述】:
我在尝试使用我的 servlet 打印 HTML 表格时遇到了一个令人困惑的错误。最后一行打印 4/8 个元素,然后停止。前 7 行没有问题,与第 8 行基本一致。
这是我的 Java 代码:
...
out.println("<tr>");
j = 0;
for (int i=56; i<64; i++){
j++;
Integer.toString(j);
out.println("<td ");
if (seats[i].label.equals(label)){
seats[i].booked = true;
seats[i].id = id;
seats[i].phone = phone;
seats[i].address = address;
seats[i].email = email;
}
if (!seats[i].booked){
out.println("bgcolor='#7CFC00'");
}
out.println("><a");
if (!seats[i].booked){
out.println(" href='Booking?label=H"+j+"'");
}
out.println(">H"+j+"</a></td>");
}
out.println("</trr");
这是我的浏览器生成的 HTML 代码:
...
<tr>
<td bgcolor="#7CFC00"><a
href="http://localhost:8080/assignment1/Booking?
label=H1">H1</a></td>
<td bgcolor="#7CFC00"><a
href="http://localhost:8080/assignment1/Booking?
label=H2">H2</a></td>
<td bgcolor="#7CFC00"><a
href="http://localhost:8080/assignment1/Booking?
label=H3">H3</a></td>
<td bgcolor="#7CFC00"><a
href="http://localhost:8080/assignment1/Booking?
label=H4">H4</a></td>
</tr></tbody></table>
座位的数组长度为 100,因此即使这就是元素不显示的原因,也有足够的空间。该循环应该执行 8 次,并显示剩余的四个必需元素,就像前 7 个循环成功执行的那样。希望得到一些帮助,因为我真的很难过,需要在为时已晚之前完成我的第一个 servlet 任务。
【问题讨论】:
标签: java html servlets html-table