- /**
- * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * The Java source code is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
shall
- * not disclose such Confidential Information and shall use it only in
- * accordance with the terms of the license agreement you entered into
- * with Sun.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.util.*;
- import java.io.*;
- /**
- * @author Tony Squier
- * @version 1.8 97/02/10 13:29:25
- */
- public class RegisterServlet extends HttpServlet
- {
- /**
- * The UserRegistry implementation that provides access to a storage
of users.
- */
- private UserRegistry _registry;
- /**
- * @param stub Arguments passed by the Servlet loader
- * @return void
- */
- public void init (ServletConfig config) throws ServletException
- {
- super.init(config);
- _registry = new UserRegistryJdbcImpl();
- }
- /**
- * Main service routine - do a register.
- * @param request The HttpServletRequest.
- * @param response The HttpServletResponse.
- * @throws ServletException
- * @throws IOException
- */
- public void service (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
- {
- // Check for valid fields
- String userId = request.getParameter ("UserId");
- String password = request.getParameter ("Password");
- String email = request.getParameter ("Email");
- if ( userId != null &&
password != null )
- {
- // Check for a duplicate
- try
- {
- JDCMember members[] =
_registry.getMember (userId);
- if ( members.length > 0 )
- {
- // Duplicate
- response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The UserId you've chosen
already exist, please go back and pick another one.");
- }
- else
- {
- JDCMember member = new JDCMember ();
- member.setUserId (userId);
- member.setPassword (password);
- member.setEmail (email);
- _registry.setMember (member);
- response.sendRedirect
("/servlet/SessionServlet?action=showLogin");
- }
- }
- catch (JDCAdminException e)
- {
- e.printStackTrace();
- response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "A problem occured with
our database, please try again later.");
- }
- }
- else
- {
- // Show the register page again.
- response.sendError
(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Please go back and
provide both a User Id and Password");
- }
- }
- }
|