jsp最近浏览

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值