问题描述
这个就不能生成class文件packageiteam;importjava.util.*;importjava.sql.*;importjava.text.*;publicclassShoppingCart{HashMapitems=null;publicShoppingCart(){items=newHashMap();}publicsynchronizedvoidadd(StringISBN)throwsException{if(items.containsKey(ISBN)){ShoppingCartItemitem=(ShoppingCartItem)items.get(ISBN);item.quantity++;}else{Stringsql="select*fromindentwhereISBN='"+ISBN+"'";DBHandledbhandle=newDBHandle();ResultSetrs=dbhandle.executeQuery(sql);ShoppingCartItemnewItem=newShoppingCartItem();if(rs.next()){newItem.ISBN=rs.getString("ISBN");newItem.name=rs.getString("name");newItem.category=rs.getString("category");newItem.provanence=rs.getString("provenance");newItem.price=rs.getFloat("price");newItem.quantity=1;dbhandle.closeResource();items.put(ISBN,newItem);}}}publicsynchronizedvoidsetItem(StringISBN,intnum){if(items.containsKey(ISBN)){ShoppingCartItemitem=(ShoppingCartItem)items.get(ISBN);item.quantity=num;}}publicsynchronizedvoidremove(StringISBN){items.remove(ISBN);}publicsynchronizedIteratorgetItems(){Collectionc=items.values();returnc.iterator();}protectedvoidfinalize()throwsThrowable{items.clear();}publicsynchronizedintgetNumberOfItems(){returnitems.size();}publicsynchronizeddoublegetTotal(){doubleamount=0.0;for(Iteratori=getItems();i.hasNext();){ShoppingCartItemitem=(ShoppingCartItem)i.next();amount+=item.quantity*item.price;}returnroundOff(amount);}privatedoubleroundOff(doublex){longval=Math.round(x*100);returnval/100;}publicsynchronizedvoidclear(){items.clear();}publicintpayOrder(Stringusername,Stringtruename,Stringpostcode,Stringaddress,Stringtelephone,Stringmemo)throwsException{Connectionconn=null;intorderID=0;DBHandledbhandle=newDBHandle();try{conn=dbhandle.getConnection();conn.setAutoCommit(false);Statementstmt=conn.createStatement();doubletotal=getTotal();SimpleDateFormatdataFormat=newSimpleDateFormat("yyyy-MM-dd-HH:mm:ss");StringorderDate=dataFormat.format(newjava.util.Date());Stringsql="insertintoindent(username,truename,address,postcode,"+"telephone,memo,totalPrice,isPay,isDeliver,orderDate)values('"+username+"','"+truename+"','"+address+"','"+postcode+"','"+telephone+"','"+memo+"',"+total+",'0','0','"+orderDate+"')";System.out.print(sql);stmt.executeUpdate(sql);sql="selectmax(orderID)asmaxOrderIDfromindent";System.out.println(sql);ResultSetrs=stmt.executeQuery(sql);rs.next();orderID=rs.getInt(1);Iteratori=getItems();while(i.hasNext()){ShoppingCartItemitem=(ShoppingCartItem)i.next();intquantity=item.quantity;StringISBN=item.ISBN;doubleprice=item.price;sql="inserintoindent(ISBN,quantity,price,orderID)values("+ISBN+","+quantity+","+price+","+orderID+")";stmt.executeUpdate(sql);}conn.commit();conn.setAutoCommit(true);}catch(Exceptionex){conn.rollback();System.out.println(ex.getMessage());}finally{dbhandle.closeResource();}returnorderID;}....................................................................它调用的是这个类:packageiteam;publicclassShoppingCartItem{publicStringISBN=null;publicStringname=null;publicfloatprice=0.0F;publicStringimage=null;publicStringprovanence=null;publicStringcategory=null;publicintquantity;}}这个是JSP文件:<%@pagelanguage="java"contentType="text/html;charset=utf-8"pageEncoding="utf-8"%><%@includefile="common.jsp"%><jsp:useBeanid="cart"class="iteam.ShoppingCart"scope="session"/><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"><title>Inserttitlehere</title></head><body><%Stringdelete=request.getParameter("delete");Stringupdate=request.getParameter("update");Stringclear=request.getParameter("clear");StringISBN=request.getParameter("ISBN");intqty=0;intcount=0;if(ISBN!=null){cart.add(ISBN);}if(clear!=null){cart.clear();}if(delete!=null){cart.remove(delete);}if(update!=null){count=cart.getNumberOfItems();for(inti=1;i<count;i++){//ISBN=request.getParameter("no"+1);qty=Integer.parseInt(request.getParameter("qty"+i));cart.setItem(ISBN,qty);}}if(cart.getNumberOfItems()==0){out.println("您的购物车为空!<inputtype=buttonname=Gobackvalue=继续购物onclick=javascript:windows.location='goods.html'>");}else{%><formname="form1"method="post"action="add.jsp"><tablewidth="700"border="1"align="center"cellpadding="0"cellspacing="0"bordercolor="#2A9FFF"background="image/bg-0002.gif"><tr><tdwidth="99"><divalign="center">商品名称</div></td><tdwidth="111"><divalign="center">商品类别</div></td><tdwidth="73"><divalign="center">单价</div></td><tdwidth="57"><divalign="center">数量</div></td><tdwidth="57"><divalign="center">总价</div></td><tdwidth="171"><divalign="center">会员信息管理</div></td></tr><%inti=0;while(cart.getItems().hasNext()){ShoppingCartItemitem=(ShoppingCartItem)cart.getItems().next();i++;%><tr><tdheight="35"><divalign="center"><%=item.ISBN%></div></td><td><divalign="center"><%=item.category%></div></td><td><divalign="center"><%=item.price%></div></td><td><divalign="center"><inputname="qut<%=i%>"type="text"value=<%=item.quantity%>><inputname="no<%=i%>"type="hidden"></div></td><td><divalign="center"><%=item.price*item.quantity%></div></td><td><divalign="center"><ahref="shoppingcar.jsp?delete=<%=item.ISBN%>">删除</a></div></td></tr></table><%}%><palign="center">合计:<fontcolor=red><%=cart.getTotal()%></font>元<br/><br/><inputtype="button"name="back"value="继续购物"onclick=javascript:window.location='goods.html'><inputtype="button"value="去收银台结帐"onclick=javascript:window.location=''><inputtype="submit"name="update"id="button"value="更新"><inputtype="submit"name="clear"id="button"value="清空购物车"></p></form><%}%></body></html>运行后说:org.apache.jasper.JasperException:/shoopingcart.jsp(5,2)ThevaluefortheuseBeanclassattributeiteam.ShoppingCartisinvalid.帮帮忙看看!谢谢