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

📄 registeraction.java

📁 Chinaxp 论坛源代码
💻 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.dao.Account;import org.redsoft.forum.dao.AccountDAO;import org.redsoft.forum.dao.DAOFactory;import org.redsoft.forum.exception.AccountAlreadyExistException;import org.redsoft.forum.exception.DAOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import java.io.IOException;/** * Add a user account * * @author Charles Huang * @version 1,March 10,2002 */public final class RegisterAction 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 userName = ( ( RegisterForm) form ).getUserName();	    final String password = ( ( RegisterForm) form ).getPassword();        final String email = ( ( RegisterForm) form ).getEmail();        try{            final AccountDAO dao = DAOFactory.getInstance().getAccountDAO();            dao.addAccount( new Account( userName,password,email ) );        }catch( final DAOException daoException ){            daoException.printStackTrace();            return (mapping.findForward("error"));        }catch( final AccountAlreadyExistException accountAlreadyExistException ){	        errors.add("User login", new ActionError("error.account.alreadyExist") );		}        // 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 + -