org.apache.jasper.JasperException: An exception occurred processing JSP page /details.jsp at line 104
101: }
102: }
103: Cookie cookie = new Cookie("ListViewCookie",list);
104: response.addCookie(cookie);
105: %>
106:
107: <td width="30%" bgcolor="#EEE" align="center">
//想知道这是为什么?求解
<!-- 商品详情 -->
<%
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="001.jpg" width="200" 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="001.jpg" width="120" height="90" border="1"/></a>
</dt>
<dd class="dd_name"><%=i.getName() %></dd>
<dd class="dd_city">产地:<%=i.getCity() %> 价格:<%=i.getPrice() %> ¥ </dd>
</dl>
</div>
<%
}
}
%>
<!-- 循环结束 -->
</td>
</tr>
感谢,这个回答解决了我的问题!
//1.保存list到cookie中时需要转码
Cookie cookie = new Cookie("ListViewCookie", URLEncoder.encode(list, "UTF-8"));
response.addCookie(cookie);
//2.读取cookie,遍历这个Cookies集合的时候需要解码
if(cookies!=null && cookies.length>0) {
for(Cookie c : cookies) {
if("ListViewCookie".equals(c.getName())) {
//list = c.getValue();
//由于cookie保存list的时候,经过转码,所以提取的时候也要解码
list = URLDecoder.decode(c.getValue(), "UTF-8");
}
}
}