已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年风险防范常识普及试题及答案解析
- 2026-2031中国女性时装行业市场调研与投资前景研究报告
- 2025年职业道德模拟试题及答案
- 2026年诊所与保险公司协议
- 劳动争议案件调解成功率分析
- 餐饮管理试题及解析
- 四年级上册科学教学设计-1.2《声音是怎样产生的》 教科版
- 儿科心衰应急预案演练脚本
- 2025年健康管理师高级健康管理实操技能鉴定试题及答案
- 2025麻精药品培训考试试题含参考答案
- 2025年公司财务总监年终总结(五篇)
- 水厂建设项目施工方案
- 2025湖北随州国有资本投资运营集团有限公司拟聘用人员笔试历年备考题库附带答案详解2卷
- 非洲猪瘟安全培训课件
- 2025陕西延长石油榆林煤化有限公司招聘120人笔试历年难易错考点试卷带答案解析试卷2套
- 2026中国人民大学管理职员和教师以外专业技术人员招聘考试笔试参考题库附答案解析
- 2025北京海淀高三上学期期中化学试卷和答案
- 幼小衔接阶段教育衔接策略与效果评价
- 口风琴上课课件
- 员工消防培训试题及答案
- 2025版哮喘病症状解读及护理要点
评论
0/150
提交评论