📄 editaccountaction.java
字号:
/* * XP Forum * * Copyright (c) 2002-2003 RedSoft Group. All rights reserved. * */package org.redsoft.forum.web;import org.apache.struts.action.*;import org.redsoft.forum.ForumConstants;import org.redsoft.forum.dao.Account;import org.redsoft.forum.dao.AccountDAO;import org.redsoft.forum.dao.DAOFactory;import org.redsoft.forum.exception.AccountNotFoundException;import org.redsoft.forum.exception.DAOException;import org.redsoft.forum.security.User;import javax.security.auth.Subject;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import java.io.IOException;/** * Edit a user account * * @author Eric Lao * @version 1, April 17,2002 */public final class EditAccountAction extends Action { /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final HttpSession session = request.getSession(); final ActionErrors errors = new ActionErrors(); final String oldpassword = ( ( EditAccountForm) form ).getOldpassword(); final String password = ( ( EditAccountForm) form ).getPassword(); final String email = ( ( EditAccountForm) form ).getEmail(); // Get the current user from session final Subject subject = (Subject)session.getAttribute(ForumConstants.USER_KEY); final String userName = ( (User)subject.getPrincipals( User.class ).iterator().next() ).getName(); try{ final AccountDAO dao = DAOFactory.getInstance().getAccountDAO(); final Account account = dao.findByUserName( userName ); // Verify if the input old password is the same as that in the DB if( account.getPassword().equals( oldpassword ) ){ account.setPassword( password ); account.setEmail( email ); dao.updateAccount( account ); }else{ errors.add("Edit Account", new ActionError("error.account.password") ); } }catch( final DAOException daoException ){ daoException.printStackTrace(); return (mapping.findForward("error")); }catch( final AccountNotFoundException accountNotFoundException ){ accountNotFoundException.printStackTrace(); return (mapping.findForward("error")); } // Report any errors we have discovered back to the original form if (!errors.isEmpty()) { saveErrors(request, errors); return (new ActionForward(mapping.getInput())); } // Remove the obsolete form bean if (mapping.getAttribute() != null) { if ("request".equals(mapping.getScope())) request.removeAttribute(mapping.getAttribute()); else session.removeAttribute(mapping.getAttribute()); } // Forward control to the specified success URI return (mapping.findForward("success")); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -