详情页面报错问题

来源:8-8 使用Cookie实现保存商品浏览记录

qq__3590

2017-01-21 15:08

<%@page import="java.util.ArrayList"%>
<%@page import="com.entity.Items"%>
<%@page import="com.dao.ItemsDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>商品详情</title>
<style type="text/css">
    div{
        float: left;
        margin: 5px 30px;
    }
    div dd{
        margin: 0px;
        font-size: 10pt;
    }
    div dd dd_name{
        color: blue;
    }
    div dd dd_city{
        color: #000;
    }
</style>
</head>
<body>
    <h1>商品详情</h1>
    <center>
        <table width="750" height="60" cellpadding="0" cellspacing="0" border="0">
            <tr>
            <!-- 商品详情 -->
            <%
                ItemsDao itemsDao = new ItemsDao();
                Items items = itemsDao.getOne(Integer.parseInt(request.getParameter("id")));
                if(items!=null){
            %>
                <td width="70%">
                    <table>
                        <tr>
                            <td rowspan="4"><img alt="" src="images/<%=items.getPicture() %>>" width="200px" height="150px"></td>
                        </tr>
                        <tr>
                            <td><%=items.getName() %></td>
                        </tr>
                        <tr>
                            <td>产地:<%=items.getCity() %></td>
                        </tr>
                        <tr>
                            <td>价格:¥<%=items.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")+"x";
                    //如果浏览记录超过10条,自动清零
                    String[] arr = list.split("x");
                    if(arr!=null&&arr.length>0){
                        if(arr.length>=10){
                            list=" ";
                        }
                    }
                    Cookie cookie = new Cookie("ListViewCookie",list);
                    response.addCookie(cookie);
                %>
                <!-- 浏览过的商品 -->
                <td width="30%" background="#EEE" align="center">
                    <p>您浏览过的商品</p>
                    <!-- 循环开始 -->
                    <%
                        ArrayList<Items> itemList = itemsDao.getViewList(list);
                        if(itemList!=null&&itemList.size()>0){
                            System.out.println("itemList.size="+itemList.size());
                            for(Items i : itemList){
                    %>
                    <div>
                        <dl>
                            <dt>
                                <a href="detail.jsp?id=<%=i.getId()%>"><img alt="" src="images/<%=i.getId() %>" width="150px" height="100px" 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>

http://img.mukewang.com/588308bb0001631409860419.jpg

请问这是为什么?

写回答 关注

1回答

  • 慕妹7139135
    2017-01-21 20:20:58

    数组越界

    qq__35...

    能具体说说怎么改吗?谢谢

    2017-01-22 14:13:37

    共 1 条回复 >

JAVA遇见HTML——JSP篇

Java Web入门级教程JSP,带你轻松的学习JSP基础知识

248276 学习 · 3198 问题

查看课程

相似问题