首页 > 编程 > JSP > 正文

实例讲解JSP Model2体系结构(中)

2020-06-01 23:26:45
字体:
来源:转载
供稿:网友
理解“音乐无国界”
  “音乐无国界”的主界面是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>

   <title>Music 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">

   <b>CD:</b>

   <select name=CD>

   <option>Yuan | The Guo Brothers | China | $14.95</option>

   <option>Drums of Passion | Babatunde Olatunji | Nigeria | $16.95</option>

   <option>Kaira | Tounami Diabate| Mali | $16.95</option>

   <option>The Lion is Loose | Eliades Ochoa | Cuba | $13.95</option>

   <option>Dance the Devil Away | Outback | Australia | $14.95</option>

   <option>Record of Changes | Samulnori | Korea | $12.95</option>

   <option>Djelika | Tounami Diabate | Mali | $14.95</option>

   <option>Rapture | Nusrat Fateh Ali Khan | Pakistan | $12.95</option>

   <option>Cesaria Evora | Cesaria Evora | Cape Verde | $16.95</option>

   <option>Ibuki | Kodo | Japan | $13.95</option>

   </select>

   <b>Quantity: </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">
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表