购物车功能报错,求指教
package com.servlet;
import java.io.*;
import com.bean.*;
import com.dao.CommodityDAOI;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class CartServlet
*/
@WebServlet("/CartServlet")
public class CartServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public CartServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>购物车</title>");
out.println("</head>");
out.println("<body background=\"./image/bg6.jpg\" style=\"background-size:cover\">");
out.println("<center>");
List<Commodity> cart = null;
int []count = new int[3];
int total = 0;
count[0]=0;
count[1]=0;
count[2]=0;
HttpSession session = request.getSession();
cart = (List)session.getAttribute("cart");
total = (int)session.getAttribute("number");
out.print("<h1>您购买的商品如下:</h1><br/>");
out.println("<table border='2'>");
out.println("<tr>");
out.println("<td>品名</td>");
out.println("<td>数量</td>");
out.println("</tr>");
for(Commodity cod:cart) {
if("1".equals(cod.getId())) count[0]++;
else if("2".equals(cod.getId())) count[1]++;
else count[2]++;
}
int i=0;
for(Commodity cod:CommodityDAOI.getAll()) {
out.println("<tr>");
out.print("<td>");
out.print(cod.getName()+"</td>");
out.println("</tr>");
i++;
out.println("<tr>");
out.print("<td>");
/*out.print("<td>"+count[i]+"件</td>");*/
out.println("</tr>");
}
out.println("</table>");
out.println("<a href='ListBookServlet'>返回商品列表</a><br/>");
out.println("<a href='Login.jsp'>返回首页</a><br/>");
out.println("</center>");
out.println("</body>");
out.println("</html>