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

📄 passwordactions.java

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


// IO and servlet 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.services.ProfileException;
import oracle.otnsamples.vsm.services.ProfileManagement;
import oracle.otnsamples.vsm.services.ProfileManagementHome;

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 handle password related actions like - notify
 * user of password and change password.
 * 
 * @author Sujatha
 * @version 1.0
 */
public class PasswordActions extends DispatchAction {
  /**
   * This is the action called from the Struts framework to notify an user of
   * his/her password through email
   *
   * @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 notifyPassword(
                                      ActionMapping mapping, ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
                                      throws IOException, ServletException {

    ProfileManagementHome profileHome = null;
    ProfileManagement profile         = null;

    try {
      profileHome =
        (ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
      profile = profileHome.create();
      profile.notifyPassword(
                             (String) request.getParameter("userName"),
                             request.getLocale().getLanguage());
      request.setAttribute(
                           "message",
                           MessageCache.getMessage(
                                                   "message.notification.success",
                                                   getLocale(request)));

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

      return mapping.findForward("display");
    } 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(profile != null) {
          profile.remove();
        }
      } catch(Exception ex) {
      }
    }

    return mapping.findForward("success");
  }
  /**
   * This is the action called from the Struts framework to change the password
   * of an user
   *
   * @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 changePassword(
                                      ActionMapping mapping, ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
                               throws IOException, 
                                      ServletException {

    ProfileManagementHome profileHome = null;
    ProfileManagement profile         = null;
    ActionForward forward             = mapping.findForward("display");

    try {
      profileHome =
        (ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
      profile = profileHome.create();
      profile.changePassword(
                             (String) request.getParameter("userName"),
                             (String) request.getParameter("oldpassword"),
                             (String) request.getParameter("newpassword"),
                             (String) request.getParameter("newpasswordconfirm"));
      forward = mapping.findForward("success");
      request.setAttribute(
                           "message",
                           MessageCache.getMessage(
                                                   "message.passwordchange.success",
                                                   getLocale(request)));

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

      return mapping.findForward("display");
    } 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(profile != null) {
          profile.remove();
        }
      } catch(Exception ex) {
      }
    }

    return forward;
  }
}

⌨️ 快捷键说明

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