㈠ 你是不是有一个连接mysql数据库的jsp购物车代码 能发给我吗
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.ikupao.domain.customer.BuyCart"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'customer_dish.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
欢迎您的光临!你选择了以下菜单:<br>
<table border="1">
<tr>
<td>菜的名称</td>
<td>口味</td>
<td>份量</td>
<td>售价</td>
<td>数量</td>
<td>合计</td>
<td>操作</td>
</tr>
<%
Map<Integer,BuyCart> map=(Map<Integer,BuyCart>)session.getAttribute("cart");
Set<Integer> key=map.keySet();
for(Integer k:key)
{
BuyCart cart=map.get(k);
int count=0;
count+=cart.getSum()*cart.getPrice();
%>
<tr>
<td><%=cart.getName() %></td>
<td><%=cart.getFlavorname() %></td>
<td><%=cart.getWeightname() %></td>
<td><%=cart.getPrice() %></td>
<td><%=cart.getSum() %></td>
<td><%=cart.getSum()*cart.getPrice() %></td>
<td><button onclick="location.href='/control/customerdish/customersdish!deleteCart.action?id=<%=cart.getId() %>'">删除</button></td>
</tr>
<%
}
%>
</table>
您本次一共消费${count}元!
</body>
</html>
㈡ jsp购物车代码
//shopping.html
<html>
<head><title>shopping stor</title></head>
<body>
<form action="carts.jsp" target="post">
<br>
please select the item that you want to buy
<br>
<select name="item">
<option>book:old man and the sea
<option>x-box game machine
<option>mp3 player
<option>cce
<option>book:jsp programming
<option>cd "the endless love"
<option>dvd "gone with the wind"
</select>
<br>
<input type="submit" name="submit" value="add">
<input type="submit" name="submit" value="remove">
</form>
</body>
</html>
------------------------------------------------------------------
//carts.jsp
<%@page contentType="text/html;charset=ISO8859_1" %>
<html>
<jsp:useBean id="cart" scope="session" class="test.DummyCart"/>
<jsp:setProperty name="cart" property="*"/>
<%
cart.processRequest();
%>
<br>
<ol>
you have chosen these items:
<%
String []items=cart.getItems();
for(int i=0;i<items.length;i++)
{
%>
<li><%=items[i] %></li>
<%
}
%>
</ol>
<hr>
<%@include file="shopping.htm" %>
</html>
---------------------------------------------------------------------//DummyCart.java
package test;
import javax.servlet.http.*;
import java.util.Vector;
import java.util.Enumeration;
public class DummyCart
{
Vector v = new Vector();
String submit=null;
String item= null;
private void addItem(String name)
{
v.addElement(name);
}
private void removeItem(String name)
{
v.removeElement(name);
}
public void setItem(String s)
{
item=s;
}
public void setSubmit(String s)
{
submit=s;
}
public String[] getItems()
{
String []s=new String[v.size()];
v.Into(s);
return s;
}
public void processRequest()
{
if(submit==null)
addItem(item);
if(submit.equals("add"))
addItem(item);
else if (submit.equals("remove"))
removeItem(item);
reset();
}
private void reset()
{
submit=null;
item=null;
}
}
----------------------------------------------------------------------
上面是一个简单的例子,功能都能实现,对网页效果要求更漂亮些的可做一些修改。