[英]Java servlet stops printing table half way through
尝试使用我的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分配。
我认为问题出在out.println("</trr");
。 请尝试使用out.println("</tr");
我在本地系统中评论了Main.java的以下代码(因为我没有seat.ser):
//Deseriailzing seating
/*try {
FileInputStream fileIn = new FileInputStream("seating.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
seats = (Seat[]) in.readObject();
in.close();
fileIn.close();
} catch (IOException i) {
i.printStackTrace();
out.println("IOException i");
//return;
} catch (ClassNotFoundException c) {
out.println("Employee class not found");
c.printStackTrace();
//return;
}*/
和
// ObjectOutputStream oos = null;
// FileOutputStream fout = null;
/*try {
FileOutputStream fileOut = new FileOutputStream("seating.ser");
ObjectOutputStream out2 = new ObjectOutputStream(fileOut);
out2.writeObject(seats);
out2.close();
fileOut.close();
System.out.printf("Serialized data is saved in seating.ser");
}catch(IOException i) {
i.printStackTrace();
}*/
然后执行。 一切正常,因此问题出在您的seat.ser文件中或上面的注释代码中。
这是我的Seat类(在Main.java中使用)代码:
public class Seat {
String label,phone,address,email,bookingTime;
String id="";
boolean booked;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.