1.session
2.建一个购物车的表
2.建一个购物车的表
解决方案 »
- 求匿名内部类的正确使用方法,下面是一个查询数据库的方法。求解决问题。
- 怎么处理Hibernate里的date类型?
- 在intellij idea下部署web,我哭了
- spring 对存储过程支持?
- Tomcat起动时,日志里打印的异常.
- s:checkboxlist 多选时不显示,单个选择时能显示是什么原因
- 请问j2ee的框架是什么?面试题!
- Applet中创建Socket时为什么回抛出IOException?
- 奇怪啊,Entity Bean只能Create,不能FindByPrimaryKey?
- 使用JDOM解析XML的中文问题?
- 我下的spring文档为什么都不能用啊?
- struts2 标签使用问题
<%
String user_name = (String) session.getAttribute("user_name");
if (user_name == null)
{
out.println("<script>");
out.println("window.alert('你没有登陆,请先登录!');");
out.println("window.location=('user_login.jsp');");
out.println("</script>");
}
//得到购物车信息
ArrayList orders_list = (ArrayList) session.getAttribute("orders_list");
if (orders_list == null || orders_list.size() == 0) {
out.println("<script>");
out.println("window.alert('你的购物车为空');");
out.println("window.location=('product_group.jsp');");
out.println("</script>");
} else {
SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd:HH-mm-ss");
String dateTime = sdfDateTime.format(new Date());
out.print(dateTime); //得到当时时间信息 String order_name = user_name; //订单名称
order_name += ":";
order_name += dateTime;
String product_names = "";
String order_counts = "";
String order_moneys = "";
int count = 0; //记录购买多少种商品
double order_money = 0;
double total_money = 0;
String order_datetime = dateTime;
String list_datetime = dateTime;
String result2 = null;
String result3 = null; Iterator it = orders_list.iterator();
while (it.hasNext())
{
OrderList shop = (OrderList) it.next();
if (user_name.equals(shop.getUserName()))
{
product_names += shop.getProductName() + ":";
order_counts += shop.getOrderCount() + ":";
count++;
String product_name = shop.getProductName();
int order_count = shop.getOrderCount(); String list_name = user_name;
list_name += ":";
list_name += product_name;
double product_price = 0;
String image_name = ""; String sql1 = "select product_price,image_name from products,images "
+ "where products.product_name like '%" + product_name.trim()
+ "%' and products.product_name = images.product_name"; database.setType(2); //访问数据库,提取商品相关的信息
database.setKeyword(sql1);
StringBuffer b1 = database.byKeywordInquire();
String result1 = b1.toString(); StringTokenizer stkInfo = new StringTokenizer(result1, "#");
stkInfo.nextElement();
product_price = Double.parseDouble((String) stkInfo.nextElement());
image_name = (String) stkInfo.nextElement(); order_money = product_price*order_count;
order_money = ((int)(order_money*100))/100;
order_moneys += String.valueOf(order_money) + ":";
total_money = total_money + order_money;
String sql2 = "insert into orderslist (list_name, user_name, product_name,product_price,"
+"order_count,order_money,image_name,order_name,list_datetime)"
+ " values('"
+ list_name
+ "','"
+ user_name
+ "','"
+ product_name
+ "',"
+ product_price
+ ","
+ order_count
+ ","
+ order_money
+ ",'"
+ image_name
+ "','"
+ order_name
+ "','"
+ list_datetime +"')"; database.setType(1); //访问数据库
database.setKeyword(sql2); StringBuffer b2 = database.byKeywordInquire();
result2 = b2.toString();
}
} String sql3 = "insert into orders (order_name, user_name, product_names, total_money, order_datetime)"
+ " values('" + order_name + "','" + user_name + "','" + product_names + "'," + total_money +",'" + order_datetime
+ "')";
database.setType(1); //访问数据库
database.setKeyword(sql3);
StringBuffer b3 = database.byKeywordInquire();
result3 = b3.toString();
if(result2.equals("success") && result3.equals("success"))
{
out.println("<script>");
out.println("window.alert('购物成功!感谢你购买我们的商品!');");
out.println("</script>");
}
session.removeAttribute("orders_list");
String mailContent = null;
mailContent = "<font color=blue><h2>感谢你购买我们的商品!</h2></font><br>"
+ "订单名称: " + order_name + "<br>"
+ "订单用户: " + user_name + "<br>"
+ "订单商品详细信息: <br><hr>";
mailContent += "<table width=400><tr>";
mailContent += "<td width='20%'>商品名</td>";
mailContent += "<td width='20%'>购买量</td>";
mailContent += "<td width='40%'>单个商品总价</td></tr>";
%>