1 package xdp.gacl.session; java.io.IOException; 4 import java.io.PrintWriter; 5 import java.util.List; 6 import javax.servlet.ServletException; 7 import javax.servlet.http.HttpServlet; 8 import javax.servlet.http.HttpServletRequest; 9 import javax.servlet.http.HttpServletResponse; 10 import javax.servlet.http.HttpSession; ListCartServlet extends HttpServlet { doGet(HttpServletRequest request, HttpServletResponse response) 15 throws ServletException, IOException { 16 response.setContentType("text/html;charset=UTF-8"); 17 PrintWriter out = response.getWriter(); 18 HttpSession session = request.getSession(); 19 List<Book> list = (List) session.getAttribute("list"); 20 if(list==null || list.size()==0){ 21 out.write("对不起,您还没有购买任何商品!!"); 22 return; 23 } out.write("您买过如下商品:<br>"); 27 for(Book book : list){ 28 out.write(book.getName() + "<br/>"); 29 } 30 } doPost(HttpServletRequest request, HttpServletResponse response) 33 throws ServletException, IOException { 34 doGet(request, response); 35 } 36 }