@Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            Connection connect = null;
            Statement statement = null;
            ResultSet result = null;
        
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connect =DriverManager.getConnection
            ("jdbc:mysql://localhost:3306/ImageStuck","root","password");
            statement = connect.createStatement();
             
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            String email = request.getParameter("email");
            if(username=="" || username==null){
                out.println("You need to enter a username. Please return to the registration page and enter one.");
            }
            else if(password=="" || password==null){
                out.println("You need to enter a password. Please return to the registration page and enter one.");
            }
            else{
            
             /* Add user to the database after checking availability */
                String findUser = "SELECT username FROM Users WHERE username = \"" + username + "\"";
                result = statement.executeQuery(findUser);
                if ( result.next() ){
                
                    out.println("Username " + result.getString("username") + " already exists. Please return to the registration page and choose a new one.");  
                }else{
                    String addUser = "INSERT INTO Users VALUES ('" + username + "', '" + password + "', '" + email + "' )" ;
                    statement.executeUpdate(addUser);

                    String location = "http://agdelako.no-ip.org:8080/imagestuck/home.html";
                    response.setContentType("text/html");
                    response.sendRedirect(location);
                } 
           }
         }
         catch (SQLException e){
               throw new ServletException("Servlet Could not display records.", e);
         } catch (ClassNotFoundException e) {
                throw new ServletException("JDBC Driver not found.", e);
        } 
           finally {
        try {
        if(result != null) {
        result.close();
        result = null;
        }
        if(statement != null) {
        statement.close();
        statement = null;
        }
        if(connect != null) {
        connect.close();
        connect = null;
        }
        } catch (SQLException e) {}
        }
        out.close();
    }