1、当前时间:程序代码:ShowProducts.jsp : % page import=shoppingcar.*% String path = request.getContextPath(); String basePath = request.getScheme() + :/ + request.getServerName() + + request.getServerPort() + path + /; %!DOCTYPE HTML PUBLIC -/W3C/DTD HTML 4.01 Transitional/ENhtmlheadtitleMy JSP ShowProductsJSP.
2、jsp starting pagemeta http-equiv=pragma content=no-cachecache-controlexpires0keywordskeyword1,keyword2,keyword3descriptionThis is my page/headbody bgcolor=#ffffff Map products = new HashMap(); products.put(1, new Product(, 高考数学万能解题法, 王一, 18.00);2五年高考三年模拟(高考物理)王二 40.00);3高考满分作文王三, 16.00);4五年高考三年模拟(高考
3、英语)王四, 48.00);5学霸笔记王五, 23.00);6五年高考三年模拟王六,268.00);7高考作文取胜之道王七,20.00);8高考作文必备素材武良良,17.00);9高考必刷题大卫,11.00); session.setAttribute(products, products);script language=javascript alert(这里是高考书店)/scriptform name=productForm action=http:/localhost:8088/JSPlearning/ShopCartJSP.jsp method=POSTinput type=hidde
4、n name=action value=purchasetable border= cellspacing=tr bgcolor=#CCCCCCtd 序号 /td 产品名称 作者 产品单价(¥) 图片 添加到购物车 /tr Set productIdSet = products.keySet(); Iterator it = productIdSet.iterator(); int number = 1; int n = 1; while (it.hasNext() String id = (String) it.next(); Product product = (Product) prod
5、ucts.get(id);tr%=number+%=product.getName()%=product.getDescription()%=product.getPrice()%img src=%=n+%.jpg align=leftbr/imagea href=Buy.jsp?id=&action=add target=cart购买 /tablep/p/form/body/htmlBuy.jsp Cart c = (Cart)session.getAttribute(); if(c = null) c = new Cart();, c); double totalPrice = c.get
6、TotalPrice(); request.setCharacterEncoding(GBK String action = request.getParameter( Map products = (HashMap)session.getAttribute( if(action != null & action.trim().equals(add) String id = request.getParameter(id Product p = (Product)products.get(id); CartItem ci = new CartItem(); ci.setProduct(p);
7、ci.setCount(1); c.add(ci);delete c.deleteItemById(id);update for(int i=0; ic.getItems().size(); i+) CartItem ci = c.getItems().get(i); int count = Integer.parseInt(request.getParameter(p + ci.getProduct().getId(); ci.setCount(count); String basePath = request.getScheme()+request.getServerName()+requ
8、est.getServerPort()+path+ List items = c.getItems();DOCTYPE html PUBLIC /www.w3.org/TR/html4/loose.dtdContent-Typetext/html; charset=GB18030购物车body- c的值是:%=(c = null) % items的值是:%=(items = null) % -form action=Buy.jspget/table align= border=产品ID产品名称购买数量单价总价处理 for(Iterator%=ci.getProduct().getName()
9、%text size=3 name=%= + ci.getProduct().getId() %=ci.getCount() % onkeypress=if (event.keyCode 57) event.returnValue = false; onchange=document.forms0.submit()%=ci.getProduct().getPrice() %=ci.getProduct().getPrice()*ci.getCount() %action=delete&删除%=c.getTotalPrice() %- javascript:修改td colspan=6 alig
10、n=清空购物车下单p target=view_window 现在时间:% response.setHeader(refresh,60 out.println(new Date().toLocaleString();三、实验心得与感受这次实验总体上进行的相对比较顺利,但是也出现过一些问题。做网页提示的时候一开始总会出现不提示的情况,后来把show改成了alert解决了问题。在插入图片时出现过图片不能正常添加的情况,在各个文件夹中插入图片都不能解决,后来发现可以直接在Myeclipse中粘贴,问题得到了解决。通过实验我发现,jsp语言很有趣很有意思,并且弥补了html的很多问题和缺点,方便又快捷。本次实验我直接延续了上次实验的主题,自己选的主题很有自主性,做起来也得心应手一些。在制作的过程中遇到问题也会很烦恼,但在制作完成之后就会很有成就感。通过这次实验,我继续提高了分析问题,解决问题的能力,也在试验中掌握jsp和动态网页编写的技巧,同时也复习了java的内容,可谓一举三得,也为以后课程的学习打下了良好的基础和铺垫。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1