jsp实现购物程序
时间:2009-07-02 17:12:58
作者:互联网
下面是我用JSP和数据库做的购物车的源程序:
注意:
1、重新计费部分还没有做好,大家自己动手吧!
2、下一版本将用session做。
//***p_cart.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page session="true" %>
<%@ page language="java" import="java.sql.*" %>
<%
String product_type;
String action;
int product_id;
int curpage;
//商品类型
if (re***st.getParameter("product_type")==null){
product_type="all";
}else{
product_type=re***st.getParameter("product_type");
}
//页数和商品类型参数,可以在“继续购物”时返回到上次购物的页面
if (re***st.getParameter("curpage")==null){
curpage=1;
}else{
cu***ge=java.lang.Integer.parseInt(re***st.getParameter("curpage"));
}
//动作
if (re***st.getParameter("action")==null){
action="view";
}else{
action=re***st.getParameter("action");
}
//商品编号
if (re***st.getParameter("product_id")==null){
product_id=0;
}else{
pr***ct_id=java.lang.Integer.parseInt(re***st.getParameter("product_id"));
}
int bbb;
bbb=1;
Integer num = new Integer(bbb);
//商店编号
se***on.putValue("shop_id",num);
//顾客username
se***on.putValue("guest_name","asp2001");
String guest_name=(String)se***on.getValue("guest_name");
Integer shop_id=(Integer)se***on.getValue("shop_id");
ja***lang.String sql;
ja***sql.ResultSet rs;
if (ac***n.compareTo("add")==0) {
sql="select cart_quantity from shop_cart where cart_shop_id=" + shop_id
+ " and cart_guest_id='" + guest_name + "' and cart_product_id=" + product_id ;
rs = bk***xecuteQuery(sql);
if (rs.next()){
int cart_quantity;
ca***quantity=java.lang.Integer.parseInt(rs***tString("cart_quantity"))+1;
sql="update shop_cart set cart_quantity=" + cart_quantity + " where cart_shop_id="
+ shop_id + " and cart_guest_id='" + guest_name + "' and cart_product_id=" + product_id ;
rs = bk***xecuteQuery(sql);}
else
{
sql="insert into shop_cart (cart_shop_id,cart_guest_id,cart_product_id,cart_quantity) values ('" + shop_id + "','"
+ guest_name + "','" + product_id + "',1)";
rs = bk***xecuteQuery(sql);
}
}
if (ac***n.compareTo("clear")==0) {
sql="delete from shop_cart where cart_shop_id=" + shop_id + " and cart_guest_id='" + guest_name + "'";
rs = bk***xecuteQuery(sql);
}
if (ac***n.compareTo("delete")==0) {
sql="delete from shop_cart where cart_shop_id=" + shop_id + " and cart_guest_id='"
+ guest_name + "' and cart_product_id=" + product_id ;
rs = bk***xecuteQuery(sql);
}
%>