コード例 #1
0
 private JSONObject checkout(HttpServletRequest request) throws JSONException, RemoteException {
   UserDTO user = (UserDTO) request.getSession().getAttribute(Constants.USER);
   JSONObject jsonObject = new JSONObject();
   try {
     proxy.checkout(user.getIdentifier());
     jsonObject.accumulate(Constants.STATUS, Constants.SUCCESS);
     jsonObject.accumulate(Constants.MESSAGE, Constants.TRANSACTION_COMPLETED_MSG);
   } catch (SQLException e) {
     jsonObject.accumulate(Constants.STATUS, Constants.ERROR);
     jsonObject.accumulate(Constants.MESSAGE, Constants.ERROR_SHOPPING_CART);
     e.printStackTrace();
   }
   return jsonObject;
 }
コード例 #2
0
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
    UserDTO user = (UserDTO) session.getAttribute(Constants.USER);
    if (user != null) {

      ShoppingCartDTO shoppingCart = proxy.getShoppingCart(user.getIdentifier());
      request.setAttribute(Constants.PRODUCTS, shoppingCart.getProducts());

      int cartCount = proxy.getShoppingCartItemCount(user.getIdentifier());
      request.setAttribute(Constants.CART_ITEM_COUNT, cartCount);

      request.getRequestDispatcher("pages/shoppingCart.jsp").forward(request, response);
    } else {
      request.getRequestDispatcher("pages/signIn.jsp").forward(request, response);
    }
  }
コード例 #3
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String operation = request.getParameter(Constants.OPERATION);
    System.out.println("----------------------------------" + operation);
    JSONObject jsonObject = new JSONObject();
    try {
      if (operation.equalsIgnoreCase(Constants.ADD)) {
        jsonObject = addToCart(request);
      } else if (operation.equalsIgnoreCase(Constants.REMOVE)) {
        UserDTO user = (UserDTO) request.getSession().getAttribute(Constants.USER);
        jsonObject =
            removeFromCart(
                Integer.valueOf(request.getParameter("productId")), user.getIdentifier());
      } else if (operation.equalsIgnoreCase(Constants.PAY)) {
        jsonObject = checkout(request);
      }
      response.getWriter().write(jsonObject.toString());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }