[英]Java servlet stops printing table half way through
I am encountering a confusing bug when attempting to print a HTML table with my servlet. 尝试使用我的servlet打印HTML表时遇到一个令人困惑的错误。 The last row is printing 4/8 elements and then stopping. 最后一行打印4/8元素,然后停止。 There is no problem with the first 7 rows, which are practically identical to the 8th. 前7行没有问题,实际上与第8行相同。
Here is my Java code: 这是我的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");
And here is the resulting HTML code from my browser: 这是我的浏览器生成的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>
The array length of seats is 100 so there is plenty of space even if that were why the elements are not displaying. 座位的排列长度为100,因此即使没有显示元素,也有足够的空间。 The loop should execute 8 times and show the remaining four required elements as the previous 7 loops did successfully. 该循环应执行8次,并显示剩余的四个必需元素,就像前7个循环成功完成的一样。 Would love some help as I'm honestly stumped and need to get my first servlet assignment done before it's too late. 坦白说,我希望得到一些帮助,并且需要在太晚之前完成我的第一个Servlet分配。
I think problem is at out.println("</trr");
我认为问题出在out.println("</trr");
. 。 Please try to use out.println("</tr");
请尝试使用out.println("</tr");
I have commented below code(because I don't have seating.ser) of your Main.java in my local system: 我在本地系统中评论了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;
}*/
and 和
// 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();
}*/
then executed. 然后执行。 It's working fine.So the Issue is in your seating.ser file or above commented code. 一切正常,因此问题出在您的seat.ser文件中或上面的注释代码中。
Here is my Seat class(this used in Main.java) code: 这是我的Seat类(在Main.java中使用)代码:
public class Seat {
String label,phone,address,email,bookingTime;
String id="";
boolean booked;
}
I'm attaching here output screen-shot.Please see. 我在这里附上输出屏幕截图。请看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.