%@ page language="java" contentType="text/html;Big5"%>
<%@ page import="java.util.*" %>
<%!
public void show_items(HttpSession session,JspWriter out) throws java.io.IOException
{
out.println("
列出所有購物車內的物件
");
Enumeration item_names = session.getAttributeNames();
out.println("你己經購買了下列東西:
");
out.println("");
out.println("商品名稱 | 數量 |
");
while (item_names.hasMoreElements())
{
String name = (String)item_names.nextElement();
if(name.endsWith("count"))
{
Integer count = (Integer)session.getAttribute(name);
int length = name.length();
String real_name = name.substring(0,length-5);
out.println("");
out.println(""+real_name+" | ");
out.println(""+count+" | ");
out.println("
");
}
}
out.println("
");
out.println("繼續購物");
}
%>
CH10 - ShowCartItems.jsp
<%
// 假若是第一次來購物的話
if (session.isNew())
{
String show = request.getParameter("type");
if(show == null)
{
String [] items = request.getParameterValues("items");
if(items != null)
{
for(int i=0 ; i");
out.println("回上一頁");
}
}
else
{
out.println("尚未有任何物品加入你的購物車中");
}
}
// 若不是第一次來購物時,即session.isNew()為false
else
{
String show = request.getParameter("type");
if(show == null)
{
String [] items = request.getParameterValues("items");
if (items != null)
{
for(int i=0 ; i");
out.println("回上一頁");
}
}
else
{
show_items(session,out);
}
}
%>