1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| <%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %> <%@ page import="entity.Items"%> <%@ page import="dao.ItemsDAO"%> <% 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 'details.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"> --> <style type="text/css"> div{ float:left; margin-left: 30px; margin-right:30px; margin-top: 5px; margin-bottom: 5px; } div dd{ margin:0px; font-size:10pt; } div dd.dd_name { color:blue; } div dd.dd_city { color:#000; } </style> </head> <body> <h1>商品详情</h1> <hr> <center> <table width="750" height="60" cellpadding="0" cellspacing="0" border="0"> <tr> <!-- 商品详情 --> <% ItemsDAO itemDao = new ItemsDAO(); Items item = itemDao.getItemsById(Integer.parseInt(request.getParameter("id"))); if(item!=null) { %> <td width="70%" valign="top"> <table> <tr> <td rowspan="4"><img src="images/<%=item.getPicture()%>" width="200" height="160"/></td> </tr> <tr> <td><B><%=item.getName() %></B></td> </tr> <tr> <td>产地:<%=item.getCity()%></td> </tr> <tr> <td>价格:<%=item.getPrice() %>¥</td> </tr> </table> </td> <% } %> <% String list =""; //从客户端获得Cookies集合 Cookie[] cookies = request.getCookies(); //遍历这个Cookies集合 if(cookies!=null&&cookies.length>0) { for(Cookie c:cookies) { if(c.getName().equals("ListViewCookie")) { list = c.getValue(); } } } list+=request.getParameter("id")+","; //如果浏览记录超过1000条,清零. String[] arr = list.split(","); if(arr!=null&&arr.length>0) { if(arr.length>=1000) { list=""; } } Cookie cookie = new Cookie("ListViewCookie",list); response.addCookie(cookie); %> <!-- 浏览过的商品 --> <td width="30%" bgcolor="#EEE" align="center"> <br> <b>您浏览过的商品</b><br> <!-- 循环开始 --> <% ArrayList<Items> itemlist = itemDao.getViewList(list); if(itemlist!=null&&itemlist.size()>0 ) { System.out.println("itemlist.size="+itemlist.size()); for(Items i:itemlist) { %> <div> <dl> <dt> <a href="details.jsp?id=<%=i.getId()%>"><img src="images/<%=i.getPicture() %>" width="120" height="90" border="1"/></a> </dt> <dd class="dd_name"><%=i.getName() %></dd> <dd class="dd_city">产地:<%=i.getCity() %> 价格:<%=i.getPrice() %> ¥ </dd> </dl> </div> <% } } %> <!-- 循环结束 --> </td> </tr> </table> </center> </body> </html>
|