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

📄 registeraction.java

📁 如题ServletJSP.rar 为网络收集的JSP网站源文件
💻 JAVA
字号:
/*
 * XP Forum
 *
 * Copyright (c) 2002-2003 RedSoft Group.  All rights reserved.
 *
 */
package org.redsoft.forum.web;

import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
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.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import org.redsoft.forum.web.Account;
import org.redsoft.forum.dao.AccountDAO;
import org.redsoft.forum.dao.DAOFactory;
import org.redsoft.forum.exception.AccountAlreadyExistException;


/**
 * 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 actionForm 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 perform(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 SQLException sqlException ){
            sqlException.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.empty()) {
	        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"));
    }
}//EOC

⌨️ 快捷键说明

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