1.Servlet
根据id查询
private void findbytspecid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { GoodsTypeBiz goodsTypeBiz = new GoodsTypeBizImpl(); Integer id = null; String idStr = request.getParameter("ids"); if (idStr != null && !"".equals(idStr)) { id = Integer.parseInt(idStr); } Tspec tspec= goodsTypeBiz.findbytspecid(id); //查询菜单数据 List<GoodsType> findAllMenu = goodsTypeBiz.findAllMenu(); //查询一级菜单数据 List<GoodsType> goodsTypeList = goodsTypeBiz.findAllMenu(); //查询一级菜单数据 request.setAttribute("findAllMenu", findAllMenu); //一级菜单数据 List<Goods>goodsList= goodsTypeBiz.goodsList(); request.setAttribute("goodsList", goodsList); request.setAttribute("goodsTypeList", goodsTypeList); request.setAttribute("tspec",tspec); /***********************编写最近浏览*****************************/ Cookie[]cookies=request.getCookies(); String history=null;//定义一个空的 默认没有 if (cookies!=null){ for (Cookie cookie:cookies){ if (cookie.getName().equals("history")){ history=cookie.getValue();//如果进入了if 表示之前的存的记录 先读出来 } } } if (history==null){//如果没有 就把商品id 做成最近浏览 丢进入 history=idStr;//就把当前访问的id存进入 }else{ if (history.indexOf("-")!=-1){ history=history.substring(0,history.indexOf("-")); history=idStr+"-"+history; }else{//一个 history=idStr+"-"+history; } } Cookie cookie=new Cookie("history",history); response.addCookie(cookie); /***********************编写最近浏览*****************************/ request.getRequestDispatcher("product-view.jsp").forward(request,response); }
private void findByAllanPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { GoodsTypeBiz goodsTypeBiz = new GoodsTypeBizImpl(); Integer id = null; String idStr = request.getParameter("ids"); if (idStr != null && !"".equals(idStr)) { id = Integer.parseInt(idStr); } String PageStr = request.getParameter("Page"); String PageSizeStr = request.getParameter("pagesize"); Integer Page = 0; Integer pagesize = 8; if (PageStr != null) { Page = Integer.parseInt(PageStr); } if (PageSizeStr != null) { pagesize = Integer.parseInt(PageSizeStr); } Integer totol; Integer PageCount = goodsTypeBiz.PageCount(); if (PageCount % pagesize == 0) { totol = PageCount / pagesize; } else { totol = PageCount / pagesize + 1; } if (Page < 1) { Page = 1; } List<Tspec> tspecLists = goodsTypeBiz.tspeclist(id, Page, pagesize); //查询菜单数据 List<GoodsType> findAllMenu = goodsTypeBiz.findAllMenu(); //查询一级菜单数据 List<GoodsType> goodsTypeList = goodsTypeBiz.findAllMenu(); //查询一级菜单数据 request.setAttribute("findAllMenu", findAllMenu); //一级菜单数据 List<Goods>goodsList= goodsTypeBiz.goodsList(); request.setAttribute("goodsList", goodsList); request.setAttribute("goodsTypeList", goodsTypeList); request.setAttribute("tspecLists", tspecLists); request.setAttribute("Page", Page); request.setAttribute("id", id); request.setAttribute("totol", totol); request.getRequestDispatcher("product-list.jsp").forward(request, response); }
页面代码
<div class="spacer"></div> <div class="last-view"> <h2>最近浏览</h2> <dl class="clearfix"> <c:if test="${requestScope.tspec1!=null}" > <dt><img width="54" height="54" src="img/${tspec1.goods.gBigImg}" /></dt> <dd><a href="IndexServlet.do?action=findbytspecid&ids=${tspec1.cId}">${tspec1.cName}</a></dd> </c:if> <c:if test="${requestScope.tspec2!=null}" > <dt><img width="54" height="54" src="img/${tspec2.goods.gBigImg}" /></dt> <dd><a href="IndexServlet.do?action=findbytspecid&ids=${tspec2.cId}">${tspec2.cName}</a></dd> </c:if> </dl> </div> </div>