- 时间:2021-02-11 13:51 编辑:于明加 来源:蚂蚁资源 阅读:120
- 扫一扫,手机访问
摘要:大家好,今天给大家介绍关于jsp购物车源码(购物车源代码)的相关内容,详细讲解jsp购物车代码,JSP购物车代码详解,jsp购物车的代码和数据库等,希望可以帮助到您。
jsp购物车代码,//shopping.html
请选择您要购买的项目 <%@page contentType="text/html;charset=ISO8859_1" %> ---------------------------- -------------------------------- // DummyCart.JavaPackage测试;导入javax.servlet.http。 *;进口java.util.vector;导入java.util.enumeration;公共类Dummycart {Vector v = new矢量();字符串提交= null;字符串项= null;私有void添加:{v.addelement(name);}私有void removeItem(字符串名称){v.removeElement(name);} public void setItem(string s){item = s;} public void setummit(string s){submit = s;} public string [] getItems(){String [] s = new String [v.size()]; v .copyInto; returnis} public void processRequest(){if(提交== null)additem(项目); if(submit.equals(“添加”))AddItem(项目);否则如果(提交)(“删除”))删除(项目); reset();}私人空白;项目= null;项目= null;}} ------------------------------------------------------ ---------------------------------------------------------------- --------------------------------------------------------- ---------------------------------------------------- ---- - 以上是一个简单的例子,可以实现,并且网页效果需要更精细的修改。
JSP购物车代码详解,选择1Scan散点Memvar选择2append空白收集Memvar Endscan
jsp购物车的代码和数据库,//类购物车Shoppingcart,用于参考包书店;导入java.util * ;.导入java.sql * ;.导入java.text * ;.公共类shoppingcart {hashmap项目= null; public shoppercart(){items = new hashmap();} public synchronized void add(字符串字符串)抛出异常{if(项目.containskey Item.Quantity ++;} else {string sql =“select * from tb_book,其中bookid ='”+ bookid +“'”; dbhandle dbhandle = new dbhandle(); ResultSet Rs = dbHandle.executeQuery(SQL); shoppingcartitem newitem = new shoppingcartitem(); if(rs.next()){newitem.bookid = bookid; newitem.isbn = rs.getstring(“ISBN”); newitem.bookname = rs.getstring(“bookname”); newitem.bookimage = rs.getstring(“Bookimage”); newitem.category.id = rs.getstring(“categoryid”newitem.author = rs.getstring(“作者”); newitem.price = rs.getfloat(“price”); newitem.description = rs.getstring(“描述”); newitem。数量= 1; dbhandle.closellce(); internmet.cput(bookid,newitem);}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} public synchronized void setItem(string bookid,int num){if(项目.containskey(bookid)){shoppingcartitem项目=(shoppingcartiTem)项目。项目; item.quantity = num;}} public同步void removestring bookid){emports.remove(bookid);} public synchronized iterator getItems(){集合c = items.values(); return c.iterator();受保护的void finalize()抛出throwable {items.clear(); public synchronized int getnumberofitems(){returnitement.size();}公共同步双gettotal(){double金额= 0.0; for(迭代器i =getItems(); i.hasnext();){shoppingcartiTem项目=(shoppingcartitem)i.next();金额+ = item.quantity * item.price;}返回循环(金额);私有双循环(双x){long值= math.round(x * 100); // cents返回Val / 100;}公共同步void clear(){items.clear();} publicint payordord(string username,string truenamame,字符串邮政编码,字符串地址,字符串电话,字符串备忘录)抛出异常{connection conn =空值; int orderid = 0; dbhandle dbhandle = new dbhandle();尝试{conn = dbhandle.getConnection(); conn.setautocommit(false);声明stmt = conn.createstatement(); Double Total = gettotal(); SimpleDateFormat Dataformat = New SimpleDateFormat(“Yyyy-MM-DD HH:MM:SS”);字符串orderdate = dataformat。格式(新java.util.date()); str.将SQL =“插入TB_ORDERS(INSERT TO TB_ORDERS(INSERTION TB_ORDERS)(用户名,TRUENAME,地址,邮政编码,TEL,MEMO,TELLPRICE,ISPAY,ISDeliver,Dramardate)值('”+ USERNAME +“,'+ Trueename +”',“+地址+”, '“+邮政编码+”,“+电话+”,“+备忘录+”,“+总+”,'0','0','+ orderdate +“)”; system.out.println( sql); stmt.executeUpdate(SQL); SQL =“选择最大(OrderID)从tb_orders中作为maxOrderId”; // change system.out.println(sql); suckset = stmt.executerquery(sql); rs.next() ; orderID = rs.getInt(1);项目i = getItems(); wher(i.hasnext()){shoppecartem项目=(shoppingcartiTem)i .next(); int数量= item.quality; string id =项目。 Bookid; Double Price = Item.Price; SQL =“插入TB_OrderDetail(OrderID,Bookid,数量,价格)值(”+ OrderID +“,”+“,”+ QuantIty +“,”+价格+“)”; stmt.executeUpdate(SQL); conn.commit(); conn.setautocommit(true);} catch(例外前){conn.rollback(); system.out.println(ex.getmessage());抛出前;}最后{dbhandle.closellce();} returnit;}} //书信息类,shoppingcartiTempackage书店;公共类ShoppingCartItem {公共字符串Bookid = null;公共字符串ISBN = null;公共字符串BookName = null;公共浮标价格= 0.0f;公共字符串描述= null; public字符串bookimage = null;公共字符串作者= null;公共字符串cartociationid = null;公共INT数量;
责任编辑(
于明加)
以上就是关于**jsp购物车源码,购物车源代码**的全部内容,了解更多请关注蚂蚁资源网。
- hedianshui
- jsp购物车共享下谢谢, 最好有详细代码! 急,session 保存用户购物车信息 shoplist,购买一个商品 就往集合里面存入一个商品实体。
- 2021-02-11 13:51:57
- wolf8668
- 这是其中的一段代码,要项目的话加445899710HttpSession session = request.getSession(false);if(session==null){dispatcher = request.getRequestDispatcher("show.jsp"); dispatcher.forward(request, response);}FoodBean foodBean = (FoodBean)session.getAttribute("FoodToAdd");Map cart = (Map)session.getAttribute("cart");if(cart==null){cart = new HashMap();session.setAttribute("cart", cart);}CartItemBean cartItem = (CartItemBean)cart.get(foodBean.getFoodID());if(cartItem==null){cart.put(foodBean.getFoodID(), new CartItemBean(foodBean,1));}else{cartItem.setNumber(cartItem.getNumber()+1);}
- 2021-02-11 13:51:57
- ydcker
- jsp购物车实现!需要使用到session,Map等等!!\~~~~~
- 2021-02-15 15:30:01