1. The rebilling part has not been done yet, so everyone can do it yourself!
2. The next version will be done with session.
//shop_cart.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page session="true" %>
<%@ page language="java" import=".*" %>
<jsp:useBean scope="page" class="" />
<%
String product_type;
String action;
int product_id;
int curpage;
//Product Type
if (("product_type")==null){
product_type="all";
}else{
product_type=("product_type");
}
//The page count and product type parameters can be returned to the page of the last shopping when "continue shopping"
if (("curpage")==null){
curpage=1;
}else{
curpage=(("curpage"));
}
//action
if (("action")==null){
action="view";
}else{
action=("action");
}
//Product number
if (("product_id")==null){
product_id=0;
}
else{
product_id=(
("product_id"));
}
int bbb;
bbb=1;
Integer num = new Integer(bbb);
//Shop Number
("shop_id",num);
//Customer username
("guest_name","asp2001");
String guest_name=(String)("guest_name");
Integer shop_id=(Integer)("shop_id");
sql;
rs;
if (("add")==0) {
sql="select cart_quantity from shop_cart where "
+ "cart_shop_ and cart_guest_id=""
+ guest_name + "" and cart_product_cart_quantity"))+1;
sql="update shop_cart set cart_quantity="
+ cart_quantity + " where cart_shop_ and cart_guest_id="" + guest_name
+ "" and cart_product_insert into shop_cart (cart_shop_id,cart_guest_id,"
+"cart_product_id,cart_quantity) values ("" + shop_id
+ "","" + guest_name + "","" + product_id + "",1)";
rs = (sql);
}
}
if (("clear")==0) {
sql="delete from shop_cart where cart_shop_ and cart_guest_id="" + guest_name + """;
rs = (sql);
}
if (("delete")==0) {
sql="delete from shop_cart where cart_shop_ and cart_guest_id="" + guest_name + "" and cart_product_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>Shopping cart</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%>">Continue shopping</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: [0].submit()">Rebill</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%>">Clear the shopping cart</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">Confirm purchase</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">Product name</td>
<td width="10%" height="8" align="left">market price</td>
<td width="10%" height="8" align="left">Promotional Price</td>
<td width="10%" height="8" align="left">quantity</td>
<td width="14%" height="8" align="left">subto</td>
<td width="12%" height="8" align="left">Download ratio</td>
<td width="17%" height="8" align="left">Download Subtotal</td>
<td width="17%" height="8" align="left">Delete</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_ and shop_cart.cart_guest_id="" + guest_name
+ "" and shop_cart.cart_product_id=shop_product.product_id";
rs = (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 (()){
while (()) {
product_id=((1));
product_name=(2);
product_price=((3));
product_discount=((4));
cart_quantity=((5));
product_first=((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>Total</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>Total deposit</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>Balance</td>
<td width="36%" colspan="2" height="16">
<div align="left"><%=total-total_first%>
</td>
</tr>
</table>
</center></div>
<%
}else{
%>
<p align="center">The shopping cart is empty!</p>
<%
}
%>
Database operation part
The program uses two tables:
1 shop_cart table
cart_id int Shopping cart number Automatic number
cart_shop_id nvarchar Shop number
cart_product_id nvarchar Product number
cart_quantity int Product quantity
Temporary storage of shopping cart data
2 shop_product table
product_id int Product number Automatic number
shop_id nvarchar Shop number
product_name nvarchar Product name
product_bb nvarchar Product Introduction
product_price int market price
product_discount int discount price
product_img img Picture
product_status nvarchar status
product_first int deposit ratio
product_type nvanchar Product Type
Store product information
Use made javabean: can provide operations on the database.
In addition, you need to register in the system DSN of the control panel.
This allows JSP to call the SQL database through JDBC-ODBC.
Calling javabean in the page can basically use the following method:
<%@ page language="java" import=".*" %>
<jsp:useBean scope="page" class="" />
<%
String sql="select * from xxx";
ResultSet rs = (sql);
if(()) {
();
();
("register_message","duplicate name found!");
}
%>
Note that rs should be turned off after use.
The following is the source program. Note that before using it, you need to compile it into a class file, namely a javabean.
--shop/--
package shop;
import .*;
public class bka {
String sDBDriver = "";
String sConnStr = "jdbc:odbc:bka";
Connection conn = null;
ResultSet rs = null;
public bka() {
try {
(sDBDriver);
}
catch( e) {
("bka(): " + ());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = (sConnStr,"xxx","yyy");
Statement stmt = ();
rs = (sql);
}
catch(SQLException ex) {
(": " + ());
}
return rs;
}
} 1. The rebilling part has not been done yet, so everyone can do it yourself!
2. The next version will be done with session.
//shop_cart.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page session="true" %>
<%@ page language="java" import=".*" %>
<jsp:useBean scope="page" class="" />
<%
String product_type;
String action;
int product_id;
int curpage;
//Product Type
if (("product_type")==null){
product_type="all";
}else{
product_type=("product_type");
}
//The page count and product type parameters can be returned to the page of the last shopping when "continue shopping"
if (("curpage")==null){
curpage=1;
}else{
curpage=(("curpage"));
}
//action
if (("action")==null){
action="view";
}else{
action=("action");
}
//Product number
if (("product_id")==null){
product_id=0;
}
else{
product_id=(
("product_id"));
}
int bbb;
bbb=1;
Integer num = new Integer(bbb);
//Shop Number
("shop_id",num);
//Customer username
("guest_name","asp2001");
String guest_name=(String)("guest_name");
Integer shop_id=(Integer)("shop_id");
sql;
rs;
if (("add")==0) {
sql="select cart_quantity from shop_cart where "
+ "cart_shop_ and cart_guest_id=""
+ guest_name + "" and cart_product_cart_quantity"))+1;
sql="update shop_cart set cart_quantity="
+ cart_quantity + " where cart_shop_ and cart_guest_id="" + guest_name
+ "" and cart_product_insert into shop_cart (cart_shop_id,cart_guest_id,"
+"cart_product_id,cart_quantity) values ("" + shop_id
+ "","" + guest_name + "","" + product_id + "",1)";
rs = (sql);
}
}
if (("clear")==0) {
sql="delete from shop_cart where cart_shop_ and cart_guest_id="" + guest_name + """;
rs = (sql);
}
if (("delete")==0) {
sql="delete from shop_cart where cart_shop_ and cart_guest_id="" + guest_name + "" and cart_product_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>Shopping cart</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%>">Continue shopping</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: [0].submit()">Rebill</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%>">Clear the shopping cart</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">Confirm purchase</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">Product name</td>
<td width="10%" height="8" align="left">market price</td>
<td width="10%" height="8" align="left">Promotional Price</td>
<td width="10%" height="8" align="left">quantity</td>
<td width="14%" height="8" align="left">subto</td>
<td width="12%" height="8" align="left">Download ratio</td>
<td width="17%" height="8" align="left">Download Subtotal</td>
<td width="17%" height="8" align="left">Delete</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_ and shop_cart.cart_guest_id="" + guest_name
+ "" and shop_cart.cart_product_id=shop_product.product_id";
rs = (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 (()){
while (()) {
product_id=((1));
product_name=(2);
product_price=((3));
product_discount=((4));
cart_quantity=((5));
product_first=((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>Total</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>Total deposit</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>Balance</td>
<td width="36%" colspan="2" height="16">
<div align="left"><%=total-total_first%>
</td>
</tr>
</table>
</center></div>
<%
}else{
%>
<p align="center">The shopping cart is empty!</p>
<%
}
%>
Database operation part
The program uses two tables:
1 shop_cart table
cart_id int Shopping cart number Automatic number
cart_shop_id nvarchar Shop number
cart_product_id nvarchar Product number
cart_quantity int Product quantity
Temporary storage of shopping cart data
2 shop_product table
product_id int Product number Automatic number
shop_id nvarchar Shop number
product_name nvarchar Product name
product_bb nvarchar Product Introduction
product_price int market price
product_discount int discount price
product_img img Picture
product_status nvarchar status
product_first int deposit ratio
product_type nvanchar Product Type
Store product information
Use made javabean: can provide operations on the database.
In addition, you need to register in the system DSN of the control panel.
This allows JSP to call the SQL database through JDBC-ODBC.
Calling javabean in the page can basically use the following method:
<%@ page language="java" import=".*" %>
<jsp:useBean scope="page" class="" />
<%
String sql="select * from xxx";
ResultSet rs = (sql);
if(()) {
();
();
("register_message","duplicate name found!");
}
%>
Note that rs should be turned off after use.
The following is the source program. Note that before using it, you need to compile it into a class file, namely a javabean.
--shop/--
package shop;
import .*;
public class bka {
String sDBDriver = "";
String sConnStr = "jdbc:odbc:bka";
Connection conn = null;
ResultSet rs = null;
public bka() {
try {
(sDBDriver);
}
catch( e) {
("bka(): " + ());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = (sConnStr,"xxx","yyy");
Statement stmt = ();
rs = (sql);
}
catch(SQLException ex) {
(": " + ());
}
return rs;
}
}