慕数据7462576
2018-01-05 11:39
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="dao.ItemsDao" %>
<%@ page import="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>详情信息</title>
</head>
<body>
<h1>商品详情</h1>
<hr>
<center>
<table width="750" height="60" cellpadding="0" cellspacing="0" border="0">
<tr>
<%
ItemsDao itemsdao = new ItemsDao();
Items items = itemsdao.getItemsById(Integer.parseInt(request.getParameter("id")));
if(items!= null)
{
%>
<td width="70%" valign="top">
<table>
<tr>
<td rowspan="4"><img src="image/<%=items.getPicture() %>" width="200" height="160"></td>
</tr>
<tr>
<td><%=items.getName() %></td>
</tr>
<tr>
<td>产地:<%=items.getCity() %></td>
</tr>
<tr>
<td>价格:¥<%=items.getPrice() %></td>
</tr>
</table>
</td>
<%
}
%>
<%
String list = "";
Cookie[] cookie = request.getCookies();
if(cookie != null && cookie.length>0){
for(Cookie c:cookie){
if(c.getName().equals("ListCookie")){
list = c.getValue();
}
}
}
list += request.getParameter("id")+",";
String[] str = list.split(",");
if(str != null && str.length > 0){
if(str.length >= 1000){
list = "";
}
}
Cookie cookies = new Cookie("ListCookie",list);
response.addCookie(cookies); /// 这儿报错了、、、、、、
%>
<td width="30%" char="#EEE" align="center">
<p>您浏览过的商品:</p>
<div>
<%
ArrayList<Items> itemslist = itemsdao.getCookieList(list);
if(itemslist != null && itemslist.size()>0){
for(Items i:itemslist){
%>
<dl>
<dt>
<a href="detail.jsp?id=<%=i.getId() %>"><img width="230" height="200" border="" src="image/<%=i.getPicture()%>"></a>
</dt>
<dd><%=i.getName() %></dd>
<dt>产地:<%=i.getCity() %> 价格:<%=i.getPrice() %></dt>
</dl>
</div>
<%}
}%>
</td>
</tr>
</table>
</center>
</body>
</html>
牛逼的回答可以奥
如果是用的eclipse开发工具,则需要解码转码,然后导入java.net.*包就行了
//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");
}
}
}
前面有人已经解答了。
报这个错 啥意思啊??
JAVA遇见HTML——JSP篇
248277 学习 · 3071 问题
相似问题