📄 profileupdateactions.java
字号:
/*
* @author : Sujatha
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : ProfileUpdateActions.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 the user profile.
*
* @author Sujatha
* @version 1.0
*/
public class ProfileUpdateActions extends DispatchAction {
/**
* This is the action called from the Struts framework to display the 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 displayProfile(
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();
ProfileForm userProfile =
new ProfileForm(profile.getProfile((String) request.getSession()
.getAttribute("userName")));
request.setAttribute("profile", userProfile);
// Get the list of countries
TreeMap countriesList = profile.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(profile != null) {
profile.remove();
}
} catch(Exception ex) {
}
}
return mapping.findForward("display");
}
/**
* This is the action called from the Struts framework to update the 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 updateProfile(
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.updateProfile(new Profile(
(String) request.getSession()
.getAttribute("userName"),
profile.getFirstName(),
profile.getLastName(),
profile.getEmail(),
profile.getAddress(),
profile.getCity(),
profile.getState(),
profile.getCountryID(),
profile.getZip(), profile.getPhone(),
null, null,
profile.getCardProvider(),
profile.getCardNumber(),
profile.getCardExpiryDate()));
request.setAttribute(
"message",
MessageCache.getMessage(
"message.profileupdate.success",
getLocale(request)));
} catch(ProfileException ex) {
request.setAttribute(
"message",
MessageCache.getMessage(
ex.getMessageCode(),
getLocale(request)));
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();
ActionErrors errors = new ActionErrors();
errors.add(
"ProfileError",
new ActionError("common.error", ex.getMessage()));
saveErrors(request, errors);
} finally {
try {
if(profileBean != null) {
profileBean.remove();
}
} catch(Exception ex) {
}
}
return forward;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -