每次list的值都覆盖原来的值,没有加进去,所以每次浏览历史记录都是只有一个,最新的那个
你遍历cookie就为了拿最后一个赋值给list?
<%
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("G_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);
System.out.println(cookie);
%>
<h2>浏览记录</h2>
</div>
<div class="like-pro">
<ul id="like-pro" class="product-grid">
<%
ArrayList<goods_info> goodslist = goodsinfo.getViewList(list);
if(goodslist!=null&&goodslist.size()>0 )
{
System.out.println("itemlist.size="+goodslist.size());
for(goods_info i:goodslist)
{
%>
不知道出了什么问题