String responseString = "success";
User user = (User) req.getSession().getAttribute("user");
String item = req.getParameter("item");
if (item != null)
{
HashMap shoppingCartMap = ShoppingCartManager.addToShoppingCart(
user, item);
if (shoppingCartMap == null)
{
responseString = "fail";
}
else
{
responseString = JSONUtil.convertMapToProducts(shoppingCartMap,
"cartcontents");
}
}
if (responseString != null)
{
System.out.println(responseString);
res.setContentType("text/xml");
res.setHeader("Cache-Control", "no-cache");
res.getWriter().write(responseString);
}
else
{
// If key comes back as a null, return a question mark.
res.setContentType("text/xml");
res.setHeader("Cache-Control", "no-cache");
res.getWriter().write("?");
}