Java Reference
In-Depth Information
Listing 21.6 contains the code for shop-for-books.jsp , a web page that displays a list
of topics, with hyperlinks to each book's page at an online bookstore.
LISTING 21.6
The Full Text of shop-for-books.jsp
1: <html>
2: <head>
3: <title>Shop for Books</title>
4: </head>
5: <body>
6: <h2 align=”Left”>Favorite Books</h2>
7: <%
8: String[] bookTitle = { “Catch-22”, “Something Happened”,
9: “Good as Gold” };
10: String[] isbn = { “0684833395”, “0684841215”, “0684839741” };
11: String amazonLink = “http://www.amazon.com/exec/obidos/ASIN/”;
12: String bnLink = “http://search.barnesandnoble.com/booksearch/”
13: + “isbnInquiry.asp?isbn=”;
14:
15: String store = request.getParameter(“store”);
16: if (store == null) {
17: store = “Amazon”;
18: }
19: for (int i = 0; i < bookTitle.length; i++) {
20: if (store.equals(“Amazon”))
21: out.println(“<li><a href=\”” + amazonLink + isbn[i] + “\”>” +
22: bookTitle[i] + “</a>”);
23: else
24: out.println(“<li><a href=\”” + bnLink + isbn[i] + “\”>” +
25: bookTitle[i] + “</a>”);
26: }
27: %>
28: <p>Preferred Bookstore:
29: <form action=”shop-for-books.jsp” method=”POST”>
30: <p><input type=”radio” value=”Amazon”
31: <%= (store.equals(“Amazon”) ? “ checked” : “”) %>
32: name=”store”> Amazon.Com
33: <p><input type=”radio” value=”BN”
34: <%= (store.equals(“BN”) ? “ checked” : “”) %>
35: name=”store”> Barnes & Noble
36: <p><input type=”submit” value=”Change Store”>
37: </form>
38: </body>
39: </html>
21
This page includes a form at the bottom of the page that lets users choose which book-
store they like to use for online shopping.
 
Search WWH ::




Custom Search