forked from maxliaops/Java_Web_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart_modify.jsp
More file actions
27 lines (27 loc) · 1020 Bytes
/
cart_modify.jsp
File metadata and controls
27 lines (27 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.Vector"%>
<%@ page import="com.model.Goodselement"%>
<%
Vector cart=(Vector)session.getAttribute("cart");
int ID=Integer.parseInt(request.getParameter("ID"));
int number=Integer.parseInt(request.getParameter("number"));
Vector newcart=new Vector();
float sum=0;
for(int i=0;i<cart.size();i++){
Goodselement mygoodselement=(Goodselement)cart.elementAt(i);
try{
if(mygoodselement.ID==ID){ //修改单件商品的购买数量
mygoodselement.number=number;
}
if(number!=0){
newcart.addElement(mygoodselement);
sum=sum+mygoodselement.number*mygoodselement.nowprice; //计算合计金额
}
}catch(Exception e){
out.println("<script language='javascript'>alert('您的操作有误!');history.back();</script>");
return;
}
}
session.setAttribute("cart",newcart); //将购物车中的商品保存到session中
out.println("合计总金额:<span class='word_orange'>¥"+sum+"</span>");
%>