• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

用JSP和数据库实现购物车的源程序(1)

发布: 2007-7-14 21:19 | 作者: 佚名    | 来源: 网络转载     | 查看: 38次 | 进入软件测试论坛讨论

领测软件测试网

用JSP和数据库实现购物车的源程序(1)

//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%>
&curp

age=<%=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><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="javascript: document.forms[0].submit()">重新计费</a></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_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"><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_order.asp">
确认购买</a></td>
</tr>
</table>
</center></div></td>
</tr>

剩余代码,请查看下一篇文章。

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网