【 tulaoshi.com - Java 】
理解“音乐无国界”
“音乐无国界”的主界面是JSP页 Eshop.jsp(见代码清单1)。你会注意到,这个页面几乎只作为专门的用户界面,不承担任何处理任务――是一个最理想的JSP方案。另外,请注意另一个JSP页Cart.jsp(见代码清单2)被Eshop.jsp通过指令<jsp:include page="Cart.jsp" flush="true" /包含于其中。
代码清单 1:EShop.jsp
<%@ page session="true" %
<html
<head
<titleMusic Without Borders</title
</head
<body bgcolor="#33CCFF"
<font face="Times New Roman,Times" size="+3"
Music Without Borders
</font
<hr<p
<center
<form name="shoppingForm"
action="/examples/servlet/ShoppingServlet"
method="POST"
<bCD:</b
<select name=CD
<optionYuan | The Guo Brothers | China | $14.95</option
<optionDrums of Passion | Babatunde Olatunji | Nigeria | $16.95</option
<optionKaira | Tounami Diabate| Mali | $16.95</option
<optionThe Lion is Loose | Eliades Ochoa | Cuba | $13.95</option
<optionDance the Devil Away | Outback | Australia | $14.95</option
<optionRecord of Changes | Samulnori | Korea | $12.95</option
<optionDjelika | Tounami Diabate | Mali | $14.95</option
<optionRapture | Nusrat Fateh Ali Khan | Pakistan | $12.95</option
<optionCesaria Evora | Cesaria Evora | Cape Verde | $16.95</option
<optionIbuki | Kodo | Japan | $13.95</option
</select
<bQuantity: </b<input type="text" name="qty" SIZE="3" value=1
<input type="hidden" name="action" value="ADD"
<input type="submit" name="Submit" value="Add to Cart"
</form
</center
<p
<jsp:include page="Cart.jsp" flush="true" /
</body
</html
代码清单 2:Cart.jsp
<%@ page session="true" import="java.util.*, shopping.CD" %
<%
Vector buylist = (Vector) session.getValue("shopping.shoppingcart");
if (buylist != null && (buylist.size() 0)) {
%
<center
<table border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF"
<tr
<td<bALBUM</b</td
<td<bARTIST</b</td
<td<bCOUNTRY</b</td
<td<bPRICE</b</td
<td<bQUANTITY</b</td
<td</td
</tr
<%
for (int index=0; index < buylist.size();index++) {
CD anOrder = (CD) buylist.elementAt(index);
%
<tr
<td<b<%= anOrder.getAlbum() %</b</td
<td<b<%= anOrder.getArtist() %</b</td
<td<b<%= anOrder.getCountry() %</b</td
<td<b<%= anOrder.getPrice() %</b</td
<td<b<%= anOrder.getQuantity() %</b</td
<td
<form name="deleteForm"
action="/examples