我在第一个页面设了一列复选框,想通过勾选它传递参数到购物车页面,并在购物车页面显示出来。不知道是哪出错了,复选框勾选了以后以第二个购物车页面能且只能显示数据库里第一行信息,价格也没显示。这是为什么呢?恕我才疏学浅,很多东西弄不懂,希望各位指点一下:
我第一个页面的复选框代码是这样的:
<th scope="row"><input name="wares" type="checkbox" id="check" value="<%=list.WaresId%>">
购物车的代码是这样的:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*"%>
<jsp:useBean id="db" class="com.conndb" scope="session" />
<jsp:useBean id="cart" class="com.Cart" scope="session" />
<jsp:useBean id="list" class="com.WaresList" scope="session"/>
<jsp:useBean id="one" class="com.CartWares" scope="session"/>
<%
String[] wares=request.getParameterValues("wares");
if(wares!=null)
cart.setWares(wares);
%>
<html>
<head>
<title>购物车</title>
<style type="text/css">
</style>
</head>
<%if(cart.getNumber()==0){
%>
<div align="center" >
现在购物车中没有物品<p>
<form action="wares_list.jsp" method="post">
<input type="submit" id="return" name="return" value="继续购物">
<input type="button" value="关闭页面" onClick="window.close();">
</div>
<%
}
else{
%>
<body>
<div align="center" class="b9b">购物车中的商品</div>
<form action="wares_list.jsp" method="post">
<table width="100%" border="1" cellspacing="1" cellpadding="1" bordercolordark="#6699ff" bordercolorlight="#FFFFFF">
<tr >
<th width="15%" height="25" scope="col"><span class="style1">商品种类</span></th>
<th width="17%" height="25" scope="col"><span class="style1">商品名称</span></th>
<th width="16%" height="25" scope="col"><span class="style1">商品价格</span></th>
<th width="18%" height="25" scope="col"><span class="style1">购买数量</span></th>
<th width="18%" height="25" scope="col"><span class="style1">总计</span></th>
</tr>
<%
String sql;
ResultSet rs=null;
double total=0;
double price=0;
String Sort,Name,Price;
for(int i=0;i<cart.getNumber();i++)
{
sql="select * from wares where Id="+wares[i];
rs=db.executeQuery(sql);
while(rs.next()){
Sort=rs.getString("Sort");
Name=rs.getString("Name");
Price=rs.getString("Price");
total=total+price;
%>
<tr>
<th scope="row"><div align="center"><%=Sort%></div></th>
<td><div align="center"><%=Name%></a></div></td>
<td><div align="center"><%=Price%></div></td>
<td><div align="center">
<input value=0 size=2 maxlength=2 name=number<%=i%>>
</div></td>
<td><div align="center"><%=price%></div></td>
</tr>
</table>
<br>
<div align="center">
<input type="submit" id="button" name="button" value="继续购买">
<input type="reset" id="button" onClick="window.location.href='clearcart.jsp';" value="清空购物车">
<input name="submit" type="submit" value="结帐"">
</div>
</form>
</body>
</html>
<%
cart.clearCart();
}
}
}%>