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

📄 registrationactions.java

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


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

import java.util.TreeMap;

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.ProfileForm;
import oracle.otnsamples.vsm.services.ProfileException;
import oracle.otnsamples.vsm.services.ProfileManagement;
import oracle.otnsamples.vsm.services.ProfileManagementHome;
import oracle.otnsamples.vsm.services.data.Profile;

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;
import org.apache.struts.actions.DispatchAction;


/**
 * This action class is used to manage user registration actions.
 * 
 * @author Sujatha
 * @version 1.0
 */
public class RegistrationActions extends DispatchAction {
  /**
   * This is the action called from the Struts framework to create an user
   * profile
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward addUser(
                               ActionMapping mapping, ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
                               throws IOException, ServletException {

    ProfileManagementHome profileHome = null;
    ProfileManagement profileBean     = null;
    ProfileForm profile               = (ProfileForm) form;
    ActionForward forward             = mapping.findForward("success");

    try {
      profileHome =
        (ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
      profileBean = profileHome.create();
      profileBean.register(new Profile(
                                       profile.getUserName(),
                                       profile.getFirstName(),
                                       profile.getLastName(), profile.getEmail(),
                                       profile.getAddress(), profile.getCity(),
                                       profile.getState(),
                                       profile.getCountryID(), profile.getZip(),
                                       profile.getPhone(), null,
                                       profile.getPassword(),
                                       profile.getCardProvider(),
                                       profile.getCardNumber(),
                                       profile.getCardExpiryDate()));
      request.setAttribute(
                           "message",
                           MessageCache.getMessage(
                                                   "message.registration.success",
                                                   getLocale(request)));

    } catch(ProfileException ex) {
      ex.printStackTrace();
      request.setAttribute(
                           "message",
                           MessageCache.getMessage(
                                                   ex.getMessageCode(),
                                                   getLocale(request)));

      // Get the registration information specified by user along with the list
      // list of countries. Set the same in request scope
      request.setAttribute("profile", profile);
      forward = mapping.findForward("display");

      try {

        TreeMap countriesList = profileBean.getCountriesList();
        request.setAttribute("countries", countriesList);
      } catch(Exception e) {
        forward = mapping.findForward("error");
      }
    } catch(Exception ex) {
      ex.printStackTrace();
      forward = mapping.findForward("error");
    } finally {

      try {

        if(profileBean != null) {
          profileBean.remove();
        }
      } catch(Exception ex) {
      }
    }

    return forward;
  }
  /**
   * This is the action called from the Struts framework to display the
   * registration form
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   */
  public ActionForward displayForm(
                                   ActionMapping mapping, ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                            throws IOException, 
                                   ServletException {

    ProfileManagementHome profileHome = null;
    ProfileManagement profileBean     = null;

    try {
      profileHome =
        (ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
      profileBean = profileHome.create();

      TreeMap countriesList = profileBean.getCountriesList();
      request.setAttribute("countries", countriesList);
    } catch(ProfileException ex) {

      ActionErrors errors = new ActionErrors();
      errors.add(
                 "ProfileError",
                 new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);

      return mapping.findForward("error");
    } catch(Exception ex) {

      ActionErrors errors = new ActionErrors();
      errors.add(
                 "ProfileError",
                 new ActionError("common.error", ex.getMessage()));
      saveErrors(request, errors);

      return mapping.findForward("error");
    } finally {

      try {

        if(profileBean != null) {
          profileBean.remove();
        }
      } catch(Exception ex) {
      }
    }

    return mapping.findForward("display");
  }
}

⌨️ 快捷键说明

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