大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> 购物车的源程序

购物车的源程序

时间: 2021-07-31 作者:daque

1、从新计费局部还没有做好,大师本人发端吧!2、下一本子将用session做。//shop_cart.jsp<%@ page contenttype="text/html;charset=utf8"%><%@ 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";}else{product_type=request.getparameter("product_type");} //页数和商品典型参数,不妨在“连接购物”时归来到上回购物的页面if (request.getparameter("curpage")==null){curpage=1;}else{curpage=java.lang.integer.parseint(request.getparameter("curpage"));} //举措if (request.getparameter("action")==null){action="view";}else{action=request.getparameter("action");} //商品编号if (request.getparameter("product_id")==null){product_id=0;}else{product_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 (action.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 = 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);}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 = bka.executequery(sql);}}if (action.compareto("clear")==0) {sql="delete from shop_cart where cart_shop_id=" + shop_id + " and cart_guest_id="" + guest_name + """;rs = bka.executequery(sql);} if (action.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 = bka.executequery(sql);}%><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="610" height="2"><tr><td><form method="post" action="shop_cart.jsp?action=update&product_type=<%=product_type%>&curpage=<%=curpage%>"><table border="0" cellpadding="0" cellspacing="0" width="610" height="2"><tr><td width="122" height="7"><div align="center"><center><table border="1" cellpadding="2" cellspacing="0" width="100%"bordercolorlight="#ffb468" bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p>购物车</td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><div align="center"><center><table border="1" cellpadding="2" cellspacing="0" width="100%" bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="shop_list.jsp?shop_id=<%=shop_id%>&product_type=<%=product_type%>&curpage=<%=curpage%>">连接购物</a></td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><div align="center"><center><tableborder="1" cellpadding="2" cellspacing="0" width="100%" bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="javascript: document.forms[0].submit()">从新计费</a></td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><table border="1" cellpadding="2" cellspacing="0" width="100%"  bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="shop_cart.jsp?action=clear&product_type=<%=product_type%>&curpage=<%=curpage%>">清空购物车</a></td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><table border="1" cellpadding="2" cellspacing="0" width="100%" bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="shop_order.asp">确认购置</a></td></tr></table></center></div></td></tr><tr align="center"><td width="610" height="1" colspan="5"><div align="center"><center><table border="1" cellpadding="2" cellspacing="0" width="100%"bgcolor="#fdfee2" bordercolorlight="#ffb468" bordercolordark="#ffffff" height="40"><tr><td width="20%" height="8" align="left">商品称呼</td><td width="10%" height="8" align="left">商场价</td><td width="10%" height="8" align="left">优惠价</td><td width="10%" height="8" align="left">数目</td><td width="14%" height="8" align="left">小计</td><td width="12%" height="8" align="left">定金比率</td><td width="17%" height="8" align="left">定金小计</td><td width="17%" height="8" align="left">简略</td></tr><%sql="select shop_product.product_id,shop_product.product_name,shop_product.product_price,shop_product.product_discount,shop_cart.cart_quantity,shop_product.product_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_product.product_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));%> <tr><td width="10%" height="1" align="left"><%=product_name%></td><td width="10%" height="1" align="left"><%=product_price%></td><td width="10%" height="1" align="left"><%=product_discount%></td><td width="10%" height="1" align="left"><input type="text" name="<%= "t" + product_id %>" size="3" value="<%=cart_quantity%>"></td><td width="14%" height="1" align="left"><%=product_discount*cart_quantity%></td><td width="12%" height="1" align="left"><%=product_first + "%"%></td><td width="17%" height="1" align="left"><%=product_first*product_discount*cart_quantity/100.0%></td><td width="17%" height="1"><div align="center"><center><p><a 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="center"><td width="72%" colspan="6" height="16"><div align="right"><p>合计</td><td width="36%" colspan="2" height="16"><div align="left"><%=total%></td></tr><tr align="center"><td width="72%" colspan="6" height="16"><div align="right"><p>定金合计</td><td width="36%" colspan="2" height="16"><div align="left"><%=total_first%></td></tr><tr align="center"><td width="72%" colspan="6" height="16"><div align="right"><p>节余</td><td width="36%" colspan="2" height="16"><div 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 = registerbean.executequery(sql); if(rs.next()) { rs.close();registerbean.closestmt();session.putvalue("register_message","duplicate name found!");}%>提防应在运用后将rs封闭。以次是bka.java的源步调。提防在运用前需用javac加以编写翻译变成class文献即javabean.--shop/bka.java--package shop;import java.sql.*; public class bka {string sdbdriver = "sun.jdbc.odbc.jdbcodbcdriver";string sconnstr = "jdbc:odbc:bka";connection conn = null;resultset rs = null; public bka() {try {class.forname(sdbdriver); }catch(java.lang.classnotfoundexception e) {system.err.println("bka(): " + e.getmessage());}}public resultset executequery(string sql) {rs = null;try {conn = drivermanager.getconnection(sconnstr,"xxx","yyy"); statement stmt = conn.createstatement();rs = stmt.executequery(sql);} catch(sqlexception ex) { system.err.println("aq.executequery: " + ex.getmessage());}return rs;}} 1、从新计费局部还没有做好,大师本人发端吧!2、下一本子将用session做。//shop_cart.jsp<%@ page contenttype="text/html;charset=utf8"%><%@ 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";}else{product_type=request.getparameter("product_type");} //页数和商品典型参数,不妨在“连接购物”时归来到上回购物的页面if (request.getparameter("curpage")==null){curpage=1;}else{curpage=java.lang.integer.parseint(request.getparameter("curpage"));} //举措if (request.getparameter("action")==null){action="view";}else{action=request.getparameter("action");} //商品编号if (request.getparameter("product_id")==null){product_id=0;}else{product_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 (action.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 = 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);}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 = bka.executequery(sql);}}if (action.compareto("clear")==0) {sql="delete from shop_cart where cart_shop_id=" + shop_id + " and cart_guest_id="" + guest_name + """;rs = bka.executequery(sql);} if (action.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 = bka.executequery(sql);}%><div align="center"><center><table border="0" cellpadding="0" cellspacing="0" width="610" height="2"><tr><td><form method="post" action="shop_cart.jsp?action=update&product_type=<%=product_type%>&curpage=<%=curpage%>"><table border="0" cellpadding="0" cellspacing="0" width="610" height="2"><tr><td width="122" height="7"><div align="center"><center><table border="1" cellpadding="2" cellspacing="0" width="100%"bordercolorlight="#ffb468" bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p>购物车</td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><div align="center"><center><table border="1" cellpadding="2" cellspacing="0" width="100%" bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="shop_list.jsp?shop_id=<%=shop_id%>&product_type=<%=product_type%>&curpage=<%=curpage%>">连接购物</a></td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><div align="center"><center><tableborder="1" cellpadding="2" cellspacing="0" width="100%" bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="javascript: document.forms[0].submit()">从新计费</a></td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><table border="1" cellpadding="2" cellspacing="0" width="100%"  bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="shop_cart.jsp?action=clear&product_type=<%=product_type%>&curpage=<%=curpage%>">清空购物车</a></td></tr></table></center></div></td><td width="122" height="7" style="border: medium" align="center"><table border="1" cellpadding="2" cellspacing="0" width="100%" bordercolorlight="#ffb468"bordercolordark="#ffffff" bgcolor="#ffb468"><tr><td width="100%"><div align="center"><center><p><a href="shop_order.asp">确认购置</a></td></tr></table></center></div></td></tr><tr align="center"><td width="610" height="1" colspan="5"><div align="center"><center><table border="1" cellpadding="2" cellspacing="0" width="100%"bgcolor="#fdfee2" bordercolorlight="#ffb468" bordercolordark="#ffffff" height="40"><tr><td width="20%" height="8" align="left">商品称呼</td><td width="10%" height="8" align="left">商场价</td><td width="10%" height="8" align="left">优惠价</td><td width="10%" height="8" align="left">数目</td><td width="14%" height="8" align="left">小计</td><td width="12%" height="8" align="left">定金比率</td><td width="17%" height="8" align="left">定金小计</td><td width="17%" height="8" align="left">简略</td></tr><%sql="select shop_product.product_id,shop_product.product_name,shop_product.product_price,shop_product.product_discount,shop_cart.cart_quantity,shop_product.product_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_product.product_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));%> <tr><td width="10%" height="1" align="left"><%=product_name%></td><td width="10%" height="1" align="left"><%=product_price%></td><td width="10%" height="1" align="left"><%=product_discount%></td><td width="10%" height="1" align="left"><input type="text" name="<%= "t" + product_id %>" size="3" value="<%=cart_quantity%>"></td><td width="14%" height="1" align="left"><%=product_discount*cart_quantity%></td><td width="12%" height="1" align="left"><%=product_first + "%"%></td><td width="17%" height="1" align="left"><%=product_first*product_discount*cart_quantity/100.0%></td><td width="17%" height="1"><div align="center"><center><p><a 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="center"><td width="72%" colspan="6" height="16"><div align="right"><p>合计</td><td width="36%" colspan="2" height="16"><div align="left"><%=total%></td></tr><tr align="center"><td width="72%" colspan="6" height="16"><div align="right"><p>定金合计</td><td width="36%" colspan="2" height="16"><div align="left"><%=total_first%></td></tr><tr align="center"><td width="72%" colspan="6" height="16"><div align="right"><p>节余</td><td width="36%" colspan="2" height="16"><div 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 = registerbean.executequery(sql); if(rs.next()) { rs.close();registerbean.closestmt();session.putvalue("register_message","duplicate name found!");}%>提防应在运用后将rs封闭。以次是bka.java的源步调。提防在运用前需用javac加以编写翻译变成class文献即javabean.--shop/bka.java--package shop;import java.sql.*; public class bka {string sdbdriver = "sun.jdbc.odbc.jdbcodbcdriver";string sconnstr = "jdbc:odbc:bka";connection conn = null;resultset rs = null; public bka() {try {class.forname(sdbdriver); }catch(java.lang.classnotfoundexception e) {system.err.println("bka(): " + e.getmessage());}}public resultset executequery(string sql) {rs = null;try {conn = drivermanager.getconnection(sconnstr,"xxx","yyy"); statement stmt = conn.createstatement();rs = stmt.executequery(sql);} catch(sqlexception ex) { system.err.println("aq.executequery: " + ex.getmessage());}return rs;}} 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.