问答详情
源自:8-8 使用Cookie实现保存商品浏览记录

为什么这个页面报500

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ page import="java.util.*,dao.ItemsDao,entity.Items" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<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:10px;

  }

  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="200px" 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() %>&nbsp;&nbsp;价格: ¥<%=i.getPrice()%></dd>

    </dl>

    </div>

    <% }

    }

    %>

    </td>

     </tr>

    </table>

    </center>

</body>

</html>

https://img4.mukewang.com/5b37ab9a00012a8e10760364.jpg

提问者:慕无忌5921142 2018-07-01 00:11

个回答

  • 秦罹
    2018-08-17 09:44:34

    cookie里面不能保存,应该将分隔符,改成#

  • 慕粉3701114
    2018-08-14 18:28:05

    DAO里的“,”号也要改成“#”

  • 爱吃零食的臭居居
    2018-07-23 19:46:48

    https://img1.mukewang.com/5b55c0060001a83a19201058.jpg这个问题是不是?

  • q_hwx
    2018-07-04 17:03:26

    把下面抛异常的那部分贴出来