Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package controller;
- import business.User;
- import dataaccess.UserDB;
- import java.io.IOException;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- @WebServlet(name = "membershipServlet", urlPatterns = {"/membership"})
- public class membershipServlet extends HttpServlet {
- /**
- * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- }
- /**
- * Handles the HTTP <code>POST</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- HttpSession session = request.getSession();
- String message;
- String url = "/login.jsp";
- String action = request.getParameter("action");
- if (action == null) {
- action = "start";
- }
- if (action.equals("start"))
- {
- url = "/login.jsp";
- } else if (action.equals("signup"))
- {
- String fullName = request.getParameter("fullname");
- String userName = request.getParameter("username");
- String email = request.getParameter("emailAddress");
- String password = request.getParameter("password");
- String Cpassword = request.getParameter("Cpassword");
- String birthdate = request.getParameter("birthdate");
- String questionNo = request.getParameter("questionNo");
- String answer = request.getParameter("answer");
- User user;
- user = new User(fullName, userName, email, password, birthdate, questionNo, answer);
- if(fullName == null || email == null || userName == null || Cpassword == null || password == null ||
- birthdate == null || answer == null || fullName.isEmpty() || userName.isEmpty() ||
- email.isEmpty() || password.isEmpty() || birthdate.isEmpty() || answer.isEmpty())
- {
- message = "please fill out all the fields";
- url = "/signup.jsp";
- }
- if (password != Cpassword)
- {
- message = "please make sure passwords are the same";
- url = "/signup.jsp";
- }
- if (UserDB.search(user.getEmail()) != null) {
- message = "this email address already exists. <br>"
- + "Please enter another email address";
- url = "/login.jsp";
- }
- else
- {
- try {
- UserDB.insert(user);
- url = "/home.jsp";
- } catch (SQLException ex) {
- Logger.getLogger(membershipServlet.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(membershipServlet.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- getServletContext()
- .getRequestDispatcher(url)
- .forward(request, response);
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement