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

📄 displaycartaction.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
/*
 * @author                        : Neelesh
 * @Version                       : 1.0
 *
 * Development Environment        : Oracle9i JDeveloper
 * Name of the File               : DisplayCartAction.java
 * Creation/Modification History  :
 *
 * Neelesh   14-Jan-2003      Created
 *
 */
package oracle.otnsamples.vsm.actions.mall;


// Servlet,IO and Locale API
import java.io.IOException;

import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.otnsamples.util.Utilities;
import oracle.otnsamples.vsm.services.ShoppingCart;
import oracle.otnsamples.vsm.services.data.CartItem;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


/**
 * The action class retrieves the cart details from the cart bean and places
 * them in the request.
 *
 * @author Neelesh
 * @version 1.0
 */
public class DisplayCartAction extends Action {
  /**
   * This is the action called from the Struts framework to display the
   * shopping  cart of the user
   *
   * @param <b>mapping</b> The ActionMapping used to select this instance.
   * @param <b>form</b> The optional ActionForm bean for this request.
   * @param <b>request</b> The HTTP Request we are processing.
   * @param <b>response</b> The HTTP Response we are processing.
   *
   * @return <b>ActionForward</b> The  control forward information
   *
   * @throws <b>IOException</b>
   * @throws <b>ServletException</b>
   */
  public ActionForward execute(
                               ActionMapping mapping, ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
                               throws IOException, ServletException {

    if(request.getSession().getAttribute("_cart") != null) {
      // get the shopping cart from session
      ShoppingCart cart =
        (ShoppingCart) request.getSession().getAttribute("_cart");

      try {
        CartItem[] items = cart.getCart();
        Locale locale    = cart.getUserLocale();
        // extract the cart information like items, total amount etc
        // and store them in request
        if(items != null && items.length > 0) {
          // store items in the cart in request
          request.setAttribute("cartItems", items);
          // store subtotal
          double subTotal = cart.getTotalAmountBeforeTax();
          request.setAttribute(
                               "subtotal",
                               Utilities.currencyFormat(subTotal, null));

          double tax             = cart.getTaxAmount();
          double shippingCharges = cart.getShippingCharges();
          // store shipping charges and tax
          request.setAttribute(
                               "shippingCharges",
                               Utilities.currencyFormat(shippingCharges, null));
          request.setAttribute("tax", Utilities.currencyFormat(tax, null));
          request.setAttribute(
                               "total",
                               Utilities.currencyFormat(
                                                        Utilities.round(
                                                                        subTotal +
                                                                        shippingCharges +
                                                                        tax, 2),
                                                        null));
        }
      } catch(Exception ex) {
        servlet.log("CartDisplayError", ex);
        ActionErrors errors = new ActionErrors();
        errors.add("CartError", new ActionError("error.displaycart"));
        saveErrors(request, errors);
      }
    }
    
    return mapping.findForward("success");
  }
}

⌨️ 快捷键说明

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