Java Reference
In-Depth Information
LISTING 21.9
Continued
7: <h3>Visitors Who Signed our Guestbook</h3>
8: <%
9: String id = request.getParameter(“id”);
10: boolean noSignatures = true;
11: try {
12: String filename = application.getRealPath(id + “.gbf”);
13: FileReader file = new FileReader(filename);
14: BufferedReader buff = new BufferedReader(file);
15: boolean eof = false;
16: while (!eof) {
17: String entry = buff.readLine();
18: if (entry == null)
19: eof = true;
20: else {
21: StringTokenizer entryData = new StringTokenizer(entry, “^”);
22: String name = (String) entryData.nextElement();
23: String email = (String) entryData.nextElement();
24: String url = (String) entryData.nextElement();
25: String entryDate = (String) entryData.nextElement();
26: String ip = (String) entryData.nextElement();
27: String comments = (String) entryData.nextElement();
28: out.print(“<p>From: “ + name);
29: if (!email.equals(“None”))
30: out.println(“ <” + email + “><br>”);
31: else
32: out.println(“<br>”);
33: if (!url.equals(“None”))
34: out.println(“Home Page: <a href=\”” + url + “\”>” +
35: url + “</a><br>”);
36: out.println(“Date: “ + entryDate + “<br>”);
37: out.println(“IP: “ + ip);
38: out.println(“<blockquote>”);
39: out.println(“<p>” + comments);
40: out.println(“</blockquote>”);
41: noSignatures = false;
42: }
43: }
44: buff.close();
45: } catch (IOException e) {
46: out.println(“<p>This guestbook could not be read because of an error.”);
47: log(“Guestbook Error: “ + e.toString());
48: }
49: if (noSignatures)
50: out.println(“<p>No one has signed our guestbook yet.”);
51: %>
52: <h3>Sign Our Guestbook</h3>
53: <form method=”post” action=”guestbook-post.jsp”>
54: <table border=”0” cellpadding=”5” cellspacing=”0” width=”100%”>
55: <tr>
Search WWH ::




Custom Search