tailieunhanh - Advanced Java 2 Platform HOW TO PROGRAM phần 5

JSP (Fi. 11,12) chiết xuất từ các CartItemBeans khỏi giỏ hàng, tổng số phụ mỗi mục trong giỏ hàng, tổng số tất cả các mặt hàng trong giỏ hàng và tạo ra một tài liệu XHTML cho phép khách hàng để xem các giỏ hàng trong định dạng bảng. | 686 Case Study Servlet and JSP Bookstore Chapter 11 52 53 54 55 56 57 send the user to dispatcher request response Fig. AddToCartServlet places an item in the shopping cart and invokes viewCart .jsp to display the cart contents part 2 of 2 . Viewing the Shopping Cart JSP viewCart. jsp Fi. extracts the CartItemBeans from the shopping cart subtotals each item in the cart totals all the items in the cart and creates an XHTML document that allows the client to view the cart in tabular format. This JSP uses classes from our bookstore package and from packages and . The scriptlet at lines 25-43 begins by retrieving the session attribute for the shopping cart Map line 26 . If there is no shopping cart the JSP simply outputs a message indicating that the cart is empty. Otherwise lines 34-41 create the variables used to obtain the information that is displayed in the resulting XHTML document. In particular line 34 obtains the Set of keys in Map cart. These keys are used to retrieve the CartItemBean s that represent each book in the cart. Lines 45-51 output the literal XHTML markup that begins the table that appears in the document. Lines 55-63 continue the scriptlet with a loop that uses each key in the Map to obtain the corresponding CartItemBean extracts the data from that bean calculates the dollar subtotal for that product and calculates the dollar total of all products so far. The last part of the loop body appears outside the scriptlet at lines 70-86 in which the preceding data is formatted into a row in the XHTML table. JSP expressions are used to place each data value into the appropriate table cell. After the loop completes line 90 lines 95-100 output the dollar total of all items in the cart and line 105 sets a session attribute containing the total. This value is used by process .jsp Fig. to display the dollar total as .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
170    252    4    29-03-2024
14    160    0    29-03-2024
15    176    0    29-03-2024
10    112    0    29-03-2024
1    102    1    29-03-2024
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.