package edu.uprm.ece.icom5016.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
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 edu.uprm.ece.icom5016.bean.ShoppingCart;
import edu.uprm.ece.icom5016.util.LogInChecker;

/**
 * @version 	1.0
 * @author
 */
public class ShowCartServlet extends HttpServlet {

	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		HttpSession session =  req.getSession(true);
		ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");
		if(cart == null){
			//Cart is empty
			cart = new ShoppingCart();
			//Put an empty cart
			session.setAttribute("cart", cart);
		}
		resp.sendRedirect("/icom5016/ShowCart.jsp");
		//dispatcher.forward(req, resp);
		//}
	}

	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		this.doGet(req, resp);
	}

	/* (non-Javadoc)
	 * @see javax.servlet.Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	/* (non-Javadoc)
	 * @see javax.servlet.GenericServlet#init()
	 */
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
