www.pudn.com > bookshop.zip > CartServlet.java, change:2013-07-09,size:1177b


package com.tarena.web; 
 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.util.ArrayList; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 
 
import com.tarena.bean.Book; 
import com.tarena.bean.BookItem; 
import com.tarena.bean.Cart; 
 
public class CartServlet extends HttpServlet { 
 
	public void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException { 
		    request.setCharacterEncoding("utf-8"); 
            response.setContentType("text/html;charset=utf-8"); 
 
 
            HttpSession session = request.getSession(); 
            Cart cart =(Cart)session.getAttribute("cart"); 
            if(cart==null || cart.getItems().size()==0){ 
            	request.setAttribute("items",null); 
            }else{ 
            	ArrayList<BookItem> items = cart.getItems(); 
            	request.setAttribute("items",items); 
            } 
            request.getRequestDispatcher("Cart.jsp").forward(request,response); 
	} 
 
}