FileDocCategorySizeDatePackage
ShoppingCartServlet.javaAPI DocExample1873Wed Apr 05 20:05:26 BST 2006com.oreilly.ajax.servlet

ShoppingCartServlet

public class ShoppingCartServlet extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

        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("?");
        }