<% String[] titles = {"GALAXYNOTE3","IPhone5S","Mui2"};
...titles[1]....titles[2]
//以上是购物车的内容和三个加入购物车按钮
清空购物车
<% String item = request.getParameter("itemName");
if(item != null && item.equals("emptyCart")){
Enumeration attributeNames = session.getAttributeNames();
while(attributeNames.hasMoreElements()){
String attributeName = (String)attributeNames.nextElement();
session.removeAttribute(attributeName);
}
} else if(item != null){
int m=0;
for(int i=0;i<3;i++){
if(item.equals("delete"+titles[i]))
{String attributeName = titles[i];
session.removeAttribute(attributeName);m=1;}
}
if(m==0){String attributeName = item;
session.setAttribute(attributeName,item);}
%>
购物车
- <%=attributeValue%> >删除
<% } %>
您的购物车现有 <%=k%> 件商品!
<% Enumeration attributeNames = session.getAttributeNames();
int k=0;
while(attributeNames.hasMoreElements())
{
String attributeName = (String)attributeNames.nextElement();
String attributeValue = (String)session.getAttribute(attributeName);
k++;
%>