package cn.edu.cg.controller;
import java.io.IOException;
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 cn.edu.cg.dao.BookDaoImpl;
import cn.edu.cg.domain.Book;
import cn.edu.cg.domain.Cart;
@WebServlet("/BuyServlet")
public class BuyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");//这一行功能在下一行中已经有了。
		response.setContentType("text/html; charset=UTF-8");
		String id=request.getParameter("id");
		BookDaoImpl dao=new BookDaoImpl();
		Book book = dao.find(id);
		Cart cart = (Cart) request.getSession().getAttribute("cart");
		if(cart==null){
			cart = new Cart();
			request.getSession().setAttribute("cart", cart);
		}
		
		//把书加到用户购物车中,完成购买
		cart.add(book);
		
		//response.sendRedirect("/WEB-INF/jsp/listcart.jsp");
		request.getRequestDispatcher("/listcart.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}
最近下载更多
                
                vincemokea     LV9
                4月24日
            
            
        
                微信网友_7309216833228800     LV1
                2024年12月23日
            
            
        
                592132324     LV4
                2024年12月11日
            
            
        
                2411307984     LV1
                2024年5月10日
            
            
        
                baining     LV1
                2024年5月8日
            
            
        
                taoshen95     LV16
                2024年3月22日
            
            
        
                zeng1206     LV7
                2023年12月25日
            
            
        
                周博宇     LV1
                2023年11月27日
            
            
        
                paolanya     LV2
                2023年11月13日
            
            
        
                abandan     LV4
                2023年11月5日
            
            
        
最近浏览更多
                
                vincemokea     LV9
                4月24日
            
            
        
                周 敬博     LV2
                2月18日
            
            
        
                微信网友_7313058229293056    
                2024年12月26日
            
            
                    暂无贡献等级
            
        
                微信网友_7309216833228800     LV1
                2024年12月23日
            
            
        
                592132324     LV4
                2024年12月11日
            
            
        
                小黄同学     LV8
                2024年9月29日
            
            
        
                cong58cong     LV8
                2024年6月26日
            
            
        
                liyan54188     LV2
                2024年6月25日
            
            
        
                TY0165     LV20
                2024年6月25日
            
            
        
                微信网友_7043154826989568     LV1
                2024年6月18日
            
            
        
                
    
    