1、重新計費部分還沒有做好,大家自己動手吧!
2、下一版本將用session做。
//shop_cart.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page session="true" %>
<%@ page " /> www.欧美与曽交性video,亚洲成人国产,在线精品国精品国产不卡

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

購物車的源程序


1、重新計費部分還沒有做好,大家自己動手吧!
2、下一版本將用session做。
//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";
}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);
//顧客username
session.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=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";
}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);
//顧客username
session.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;
}

jsp技術購物車的源程序,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 国外经典三级 | 男人J桶女人P视频无遮挡网站 | 亚洲AV久久无码精品九号软件 | 超污视频带污疼免费视频 | 四虎4hu亚洲精品 | 免费人妻无码AV不卡在线 | 亚洲国产亚综合在线区尤物 | 亚洲天堂2017无码 | 国产呦精品一区二区三区下载 | 亚洲精品国产在线观看 | 久久re6热在线视频精品 | 巨爆乳中文字幕爆乳区 | 国产色婷亚洲99精品AV | 秋霞电影院兔费理论观频84mb | 亚洲乱码在线卡一卡二卡新区 | 中文字幕亚洲第一 | 亚色九九九全国免费视频 | 素人约啪第五季 | 国产精品无码中文在线AV | 亚洲中文字幕在线精品 | 亲胸揉胸膜下刺激视频网站APP | 国产一级做a爰片久久毛片男 | 精品国产自在现线拍国语 | 久久欧洲AV无码精品色午夜麻豆 | 国产亚洲精品影视在线 | 强伦姧久久久久久久久久 | 久久精品视频在线看15 | 国内精品乱码卡一卡2卡三卡新区 | 久久五月综合婷婷中文云霸高清 | 中文字幕精品在线观看 | 精品 在线 视频 亚洲 | 国产扒开美女双腿屁股流白浆 | 爽爽影院线观看免费 | 在教室伦流澡到高潮H女攻视频 | 亚洲视频一 | 青青涩射射 | 成年人视频在线免费播放 | 亚洲伊人成综合人影院 | 37pao成人国产永久免费视频 | 大胸美女被C得嗷嗷叫动态图 | 亚洲日本一区二区三区在线不卡 |