用JSP与数据库做购物车源程序.docx_第1页
用JSP与数据库做购物车源程序.docx_第2页
用JSP与数据库做购物车源程序.docx_第3页
用JSP与数据库做购物车源程序.docx_第4页
用JSP与数据库做购物车源程序.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

用JSP和数据库做的购物车的源程序下面是我用JSP和数据库做的购物车的源程序:/shop_cart.jsp% page contentType=text/html;charset=gb2312% page session=true % page language=java import=java.sql.* %jsp:useBean id=bka scope=page class=shop.bka /%String product_type;String action;int product_id;int curpage;/商品类型if (request.getParameter(product_type)=null)product_type=all;elseproduct_type=request.getParameter(product_type);/页数和商品类型参数,可以在“继续购物”时返回到上次购物的页面if (request.getParameter(curpage)=null)curpage=1;elsecurpage=java.lang.Integer.parseInt(request.getParameter(curpage);/动作if (request.getParameter(action)=null)action=view;elseaction=request.getParameter(action);/商品编号if (request.getParameter(product_id)=null)product_id=0;elseproduct_id=java.lang.Integer.parseInt(request.getParameter(product_id);int bbb;bbb=1;Integer num = new Integer(bbb);/商店编号session.putValue(shop_id,num);/顾客usernamesession.putValue(guest_name,asp2001);String guest_name=(String)session.getValue(guest_name);Integer shop_id=(Integer)session.getValue(shop_id);java.lang.String sql;java.sql.ResultSet rs;if (pareTo(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 = bka.executeQuery(sql);if (rs.next()int cart_quantity;cart_quantity=java.lang.Integer.parseInt(rs.getString(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 = bka.executeQuery(sql);elsesql=insert into shop_cart (cart_shop_id,cart_guest_id,cart_product_id,cart_quantity) values ( + shop_id + ,+ guest_name + , + product_id + ,1);rs = bka.executeQuery(sql);if (pareTo(clear)=0) sql=delete from shop_cart where cart_shop_id= + shop_id + and cart_guest_id= + guest_name + ;rs = bka.executeQuery(sql);if (pareTo(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 = bka.executeQuery(sql);%div align=centercentertable border=0 cellpadding=0 cellspacing=0 width=610height=2trtdform method=POSTaction=shop_cart.jsp?action=update&product_type=%=product_type%&curpage=%=curpage%table border=0 cellpadding=0 cellspacing=0 width=610height=2trtd width=122 height=7div align=centercentertableborder=1 cellpadding=2 cellspacing=0 width=100%bordercolorlight=#FFB468 bordercolordark=#FFFFFFbgcolor=#FFB468trtd width=100%divalign=centercenterp购物车/td/tr/table/center/div/tdtd width=122 height=7 style=border: mediumalign=centerdiv align=centercentertableborder=1 cellpadding=2 cellspacing=0 width=100%bordercolorlight=#FFB468bordercolordark=#FFFFFF bgcolor=#FFB468trtd width=100%div align=centercenterpahref=shop_list.jsp?shop_id=%=shop_id%&product_type=%=product_type%&curpage=%=curpage%继续购物/a/td/tr/table/center/div/tdtd width=122 height=7 style=border: mediumalign=centerdiv align=centercentertableborder=1 cellpadding=2 cellspacing=0 width=100%bordercolorlight=#FFB468bordercolordark=#FFFFFF bgcolor=#FFB468trtd width=100%div align=centercenterpahref=javascript: document.forms0.submit()重新计费/a/td/tr/table/center/div/tdtd width=122 height=7 style=border: mediumalign=centerdiv align=centercentertableborder=1 cellpadding=2 cellspacing=0 width=100%bordercolorlight=#FFB468bordercolordark=#FFFFFF bgcolor=#FFB468trtd width=100%div align=centercenterpa href=shop_cart.jsp?action=clear&product_type=%=product_type%&curpage=%=curpage%清空购物车/a/td/tr/table/center/div/tdtd width=122 height=7 style=border: medium align=centerdiv align=centercentertableborder=1 cellpadding=2 cellspacing=0width=100% bordercolorlight=#FFB468bordercolordark=#FFFFFF bgcolor=#FFB468trtd width=100%div align=centercenterpa href=shop_order.asp确认购买/a/td/tr/table/center/div/td/trtr align=centertd width=610 height=1 colspan=5div align=centercentertable border=1 cellpadding=2 cellspacing=0 width=100%bgcolor=#FDFEE2 bordercolorlight=#FFB468bordercolordark=#FFFFFF height=40trtd width=20% height=8 align=left商品名称/tdtd width=10% height=8 align=left市场价/tdtd width=10% height=8 align=left优惠价/tdtd width=10% height=8 align=left数量/tdtd width=14% height=8 align=left小计/tdtd width=12% height=8 align=left定金比例/tdtd width=17% height=8 align=left定金小计/tdtd width=17% height=8 align=left删除/td/tr%sql=select shop_duct_id,shop_duct_name,shop_duct_price,shop_duct_discount,shop_cart.cart_quantity,shop_duct_first from shop_cart,shop_product where shop_cart.cart_shop_id=+ shop_id + and shop_cart.cart_guest_id= + guest_name + and shop_cart.cart_product_id=shop_duct_id;rs = bka.executeQuery(sql);int total;int total_first;total=0;total_first=0;String product_name;int product_price;int product_discount;int product_first;int cart_quantity;if (rs.next()while (rs.next() product_id=java.lang.Integer.parseInt(rs.getString(1);product_name=rs.getString(2);product_price=java.lang.Integer.parseInt(rs.getString(3);product_discount=java.lang.Integer.parseInt(rs.getString(4);cart_quantity=java.lang.Integer.parseInt(rs.getString(5);product_first=java.lang.Integer.parseInt(rs.getString(6);%trtd width=10% height=1 align=left%=product_name%/tdtd width=10% height=1 align=left%=product_price%/tdtd width=10% height=1 align=left%=product_discount%/tdtd width=10% height=1 align=leftinput type=text name=%= t + product_id %size=3 value=%=cart_quantity%/tdtd width=14% height=1 align=left%=product_discount*cart_quantity%/tdtd width=12% height=1 align=left%=product_first + %/tdtd width=17% height=1 align=left%=product_first*product_discount*cart_quantity/100.0%/tdtd width=17% height=1div align=centercenterpa href=shop_cart.jsp?action=delete&product_id=%=product_id%delete/a/td/tr%total=total+product_discount*cart_quantity;total_first=total_first+product_discount*cart_quantity*product_first/100;%tr align=centertd width=72% colspan=6 height=16div align=rightp总计/tdtd width=36% colspan=2 height=16div align=left%=total%/td/trtr align=centertd width=72% colspan=6 height=16div align=rightp定金总计/tdtd width=36% colspan=2 height=16div align=left%=total_first%/td/trtr align=centertd width=72% colspan=6 height=16div align=rightp结余/tdtd width=36% colspan=2 height=16div align=left%=total-total_first%/td/tr/table/center/div%else%p align=center购物车为空!/p%数据库操作部分程序用到两个表:1 shop_cart表cart_id int 购物车编号 自动编号cart_shop_id nvarchar 商店编号cart_product_id nvarchar 商品编号cart_quantity int 商品数量临时存放购物车数据2 shop_product表product_id int 商品编号 自动编号shop_id nvarchar 商店编号product_name nvarchar 商品名称product_bb nvarchar 商品介绍product_price int 市场价product_discount int 优惠价product_img img 图片product_status nvarchar 状态product_first int 定金比例product_type nvanchar 商品类型存放商品资料使用bka.java制成的javabean:bka.class可以提供对数据库的操作。另外,需在控制面板的系统DSN中注册bka.dsn,从而可使JSP通过JDBC-ODBC来调用sql数据库。在页面中调用javabean,基本上可采用以下方式:% page language=java import=java.sql.* %jsp:useBean id=RegisterBean scope=page class=shop.bka /%String sql=select * from xxx;ResultSet rs = Regist

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论