1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Cookie cookie = CookieUtils.getCookie(request.getCookies(), "history"); StringBuffer respsb = new StringBuffer(); if (null == cookie) { respsb.append("<font color='red'>没有浏览记录</font>,"); respsb.append("<a href='books.html'>浏览商品</a>"); } else { String[] books = {"西游记", "红楼梦", "水浒传", "三国志"}; String history = cookie.getValue(); String[] historys = history.split("-"); respsb.append("您的浏览记录如下:<br>"); for (String index : historys) { String bookName = books[Integer.parseInt(index)]; respsb.append(bookName).append("<br>"); } } response.setContentType("text/html;charset=utf-8"); response.getWriter().println(respsb);
|