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

📄 displayshippingaddressaction.java

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


//Servlets and IO API
import java.io.IOException;

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

import oracle.otnsamples.util.MessageCache;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.actions.forms.ShippingAddressForm;
import oracle.otnsamples.vsm.services.MallNavigation;
import oracle.otnsamples.vsm.services.MallNavigationHome;
import oracle.otnsamples.vsm.services.ServiceException;
import oracle.otnsamples.vsm.services.ShoppingCart;
import oracle.otnsamples.vsm.services.data.Country;

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 is responsible for placing the shipping address data in the
 * request.
 *
 * @author Neelesh
 * @version 1.0
 */
public class DisplayShippingAddressAction extends UpdateCartAction {
  /**
   * This is the action called from the Struts framework to display the
   * shipping  address for the current user so that the user can change it ,
   * if needed
   *
   * @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 {

    MallNavigationHome navigationHome = null;
    MallNavigation navigation         = null;
    String userName                   =
      (String) request.getSession().getAttribute("userName");

    // The user has not logged in
    if(userName == null) {
      // forward to login page
      ActionErrors errors = new ActionErrors();
      errors.add(
                 "UserNameError",
                 new ActionError(this.getResources(request).getMessage(
                                                          getLocale(request),
                                                         "error.notloggedin")));
      saveErrors(request, errors);

      return mapping.findForward("login");
    }

    // The cart is created 
    if(request.getSession().getAttribute("_cart") != null) {
      //Before we display shipping address,the cart is updated with the latest 
      //modifications by the user
      super.execute(mapping, form, request, response);

      ShoppingCart cart =
        (ShoppingCart) request.getSession().getAttribute("_cart");

      try {
        // set the user name in cart
        cart.setUserName(userName);
        // get the default shipping address
        ShippingAddressForm addressForm =
          new ShippingAddressForm(cart.getShippingAddress());
        // store this address and list of countries [to be selected by user]
        request.setAttribute("shippingAddressForm", addressForm);
        navigationHome =
          (MallNavigationHome) ServiceLocator.getLocator().getService("MallNavigation");
        navigation = navigationHome.create();
        Country[] countries = navigation.getCountries();
        request.setAttribute("countries", countries);

      } catch(ServiceException ex) {
        // handle errors
        servlet.log("DisplayShippingAddressError", ex);
        ActionErrors errors = new ActionErrors();
        errors.add(
                   "CartError",
                   new ActionError(
                                   "error.shippingaddress",
                                   MessageCache.getMessage(
                                                           ex.getMessageCode(),
                                                           getLocale(request))));
        saveErrors(request, errors);
      } catch(Exception ex) {
        servlet.log("DisplayShippingAddressError", ex);      
        ActionErrors errors = new ActionErrors();
        errors.add("CartError", new ActionError("error.shippingaddress"));
        saveErrors(request, errors);
      } finally {
        try {
          if(navigation != null) {
            navigation.remove();
          }
        } catch(Exception ex) {
        }
      }
    } else {
      // The cart is not created
      // if there is no cart,forward to error page
      ActionErrors errors = new ActionErrors();
      errors.add("CartError", new ActionError("error.shippingaddress"));
      saveErrors(request, errors);

      return mapping.findForward("nocart");
    }
    // if everything is fine, forward to shipping address JSP
    return mapping.findForward("success");
  }
}

⌨️ 快捷键说明

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