簡體   English   中英

Java servlet停止打印表一半

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM