⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productaction.java

📁 jsp网站开发四“酷”全书原码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          ActionForward forward = null;
          ProductForm form = (ProductForm)actionForm;
          try{
            CategoryProxy cpProxy = new CategoryProxy();
            ArrayList listProductCat = cpProxy.getCatLabelAddAll();
            HttpSession session = request.getSession();
            session.setAttribute("ProductCatList", listProductCat);
            if(form.getStrutsAction()==0){
              String productId = form.getProductId();
              form.clear();
              ProductModel lModel = proxy.queryProduct(productId);
              form.setProductId(lModel.getProductId());
              form.setCatId(lModel.getCatId());
              form.setCatName(lModel.getCatName());
              form.setProductName(lModel.getProductName());
              form.setListPrice(lModel.getListPrice());
              form.setProductCount(lModel.getProductCount());
              form.setProductImgUrl(lModel.getProductImgUrl());
              form.setProductDesc(lModel.getProductDesc());
              form.setOrderDesc(lModel.getOrderDesc());
              form.setRegisterTime(lModel.getRegisterTime());
              form.setProductContent(lModel.getProductContent());
            }
            else{
              proxy.updateProduct(form.getModel());
            }
          }catch(ShopException e){
            try{
              request.setAttribute(Constants.Error_Name,e.getDescription());
            }catch(Exception ee){
            }
          }catch(Exception e){
            e.printStackTrace();
            try{
              request.setAttribute(Constants.Error_Name,Utility.getMessage("Shop.Product.Error.ModifyProductError"));
            }catch(Exception ee){
            }
          }
          setMenuSession(request,"shop_purchase","shop_cart_search","");
          forward = mapping.findForward("success");
          return forward;
        }


      private ActionForward performAdd(ActionMapping mapping, ActionForm actionForm,
                                       HttpServletRequest request, HttpServletResponse response){
        ActionForward forward = null;
        ProductForm form = (ProductForm)actionForm;
        try{
          CategoryProxy cpProxy = new CategoryProxy();
          ArrayList listProductCat = cpProxy.getCatLabel();
          HttpSession session = request.getSession();
          session.setAttribute("ProductCatList", listProductCat);
          if(form.getStrutsAction()==0){
            form.clear();
          }
          else{
            //check loginName
            ProductModel lModel01 = proxy.queryProductByProductName(form.getProductName());
            if(lModel01!=null){
              throw new ShopException(Utility.getMessage("Shop.Product.Error.NameExists"));
            }
            proxy.insertProduct(form.getModel());
            form.clear();
          }
        }catch(ShopException e){
          try{
            request.setAttribute(Constants.Error_Name,e.getDescription());
          }catch(Exception ee){
          }
        }catch(Exception e){
          e.printStackTrace();
          try{
            request.setAttribute(Constants.Error_Name,Utility.getMessage("Shop.Product.Error.AddProductError"));
          }catch(Exception ee){
          }
        }
        setMenuSession(request,"admin_store","admin_product_add","");
        forward = mapping.findForward("success");
        return forward;
      }
      private ActionForward performSearchCart(ActionMapping mapping, ActionForm actionForm,
                                       HttpServletRequest request, HttpServletResponse response){
        ActionForward forward = null;
        HttpSession lSession = request.getSession();
        CartBean cartBean = (CartBean)lSession.getAttribute("cartBean");
        if (cartBean == null)
          cartBean = new CartBean();
        ArrayList lList = cartBean.getItemList();
        lSession.setAttribute("LineItem_LocalList", lList);
        lSession.setAttribute("cartBean", cartBean);
        setMenuSession(request,"shop_purchase","shop_cart_search","");
        forward = mapping.findForward("success");
        return forward;
      }
      private ActionForward performAddCartItem(ActionMapping mapping, ActionForm actionForm,
                                       HttpServletRequest request, HttpServletResponse response){
        ActionForward forward = null;
        ProductForm form = (ProductForm)actionForm;
        HttpSession lSession = request.getSession();
        CategoryProxy cpProxy = new CategoryProxy();
        CartBean cartBean = (CartBean)lSession.getAttribute("cartBean");
        if (cartBean == null)
          cartBean = new CartBean();
        String itemid = getNextItemIdSession(request);
        try{
          ItemInfo item = new ItemInfo();
          item.setItemId(itemid);
          item.setProductId(form.getProductId());
          ProductProxy lpProxy = new ProductProxy();
          ProductModel lModel = lpProxy.queryProduct(form.getProductId());
          if(lModel==null){
            throw new ShopException(Utility.getMessage("Shop.Product.Error.NameExists"));
          }
          item.setListPrice(new BigDecimal(lModel.getListPrice()));
          item.setUnitPrice(new BigDecimal(lModel.getUnitPrice()));
          cartBean.addItem(item, true);
          ArrayList lList = cartBean.getItemList();
          lSession.setAttribute("LineItem_LocalList", lList);
          lSession.setAttribute("cartBean", cartBean);
          ArrayList listProductCat = cpProxy.getCatLabelAddAll();
          lSession.setAttribute("ProductCatList", listProductCat);
          form.clear();
        }catch(ShopException e){
          try{
            request.setAttribute(Constants.Error_Name,e.getDescription());
          }catch(Exception ee){
          }
        }catch(Exception e){
          e.printStackTrace();
          try{
            request.setAttribute(Constants.Error_Name,Utility.getMessage("Shop.Product.Error.AddProductError"));
          }catch(Exception ee){
          }
        }
        setMenuSession(request,"shop_purchase","shop_cart_search","");
        forward = mapping.findForward("success");
        return forward;
      }

      private ActionForward performDeleteCartItem(ActionMapping mapping, ActionForm actionForm,
                                       HttpServletRequest request, HttpServletResponse response){
        ActionForward forward = null;
        ProductForm form = (ProductForm)actionForm;
        HttpSession lSession = request.getSession();
        CartBean cartBean = (CartBean)lSession.getAttribute("cartBean");
        if (cartBean == null)
          cartBean = new CartBean();
        try{
          cartBean.removeItemById(form.getDeleteItemId());
          ArrayList lList = cartBean.getItemList();
          lSession.setAttribute("LineItem_LocalList", lList);
          lSession.setAttribute("cartBean", cartBean);
          form.clear();
        }catch(Exception e){
          e.printStackTrace();
        }
        setMenuSession(request,"shop_purchase","shop_cart_search","");
        forward = mapping.findForward("success");
        return forward;
      }

      private ActionForward performClearCart(ActionMapping mapping, ActionForm actionForm,
                                       HttpServletRequest request, HttpServletResponse response){
        ActionForward forward = null;
        ProductForm form = (ProductForm)actionForm;
        HttpSession lSession = request.getSession();
        CartBean cartBean = (CartBean)lSession.getAttribute("cartBean");
        if (cartBean == null)
        {
          setMenuSession(request,"shop_purchase","shop_order_search","");
          forward = mapping.findForward("success");
          return forward;
        }
        try{
          cartBean.clear();
          lSession.setAttribute("LineItem_LocalList", null);
          lSession.setAttribute("cartBean", cartBean);
          form.clear();
        }catch(Exception e){
          e.printStackTrace();
        }
        setMenuSession(request,"shop_purchase","shop_cart_search","");
        forward = mapping.findForward("success");
        return forward;
      }

      private ActionForward performService(ActionMapping mapping, ActionForm actionForm,
                                       HttpServletRequest request, HttpServletResponse  response){
        ActionForward forward = null;
        HttpSession session = request.getSession();
        SessionWrapper lSessionWrapper = (SessionWrapper)session.getAttribute(Constants.Session_Wrapper);
        if (lSessionWrapper != null){
          setMenuSession(request, "shop_purchase", "shop_cart_search", "");
          forward = mapping.findForward("success");
        }else{
          setMenuSession(request,"shop_index","","");
          forward = mapping.findForward("failure");
        }
        return forward;
      }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -