Servlet

Registration Form using Servlet and Mysql

The tutorial will teach you how to make a Registration Form using Servlet and Mysql step by step. those who interest to learn servlet this is right to learn from the beginning to advanced. i have attached the video below i explained the easy way to understand programming.

Registration Form

Create the file Index.html paste the following code.

Index.html

<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </head>
    <body>
        
        <div class="container">
            <div class="row">
                <div>
                    <form action="registation" method="POST">
                        
                        <div class="form-group">   
                            <h2>Registaion</h2>  
                        </div>
                        
                         <div class="form-group">   
                             <label>First Name</label>
                             <input type="text" class="form-control" id="fname" name="fname" placeholder="Firstname" required>
                        </div>
                        
                         <div class="form-group">   
                             <label>Last Name</label>
                             <input type="text" class="form-control" id="lname" name="lname" placeholder="Lastname" required>
                        </div>
                        
                         <div class="form-group">   
                             <label>Address</label>
                             <input type="text" class="form-control" id="address" name="address" placeholder="Address" required>
                        </div>
                      
                        <div class="form-group">   
                             <label>Phone No</label>
                             <input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" required>
                        </div>
                        
                        
                        <div class="form-group">   
                           
                            <button type="submit" class="btn btn-success">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>    
    </body>
</html>

registation.java

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
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;


@WebServlet("/registation")
public class registation extends HttpServlet {

    Connection con;
    PreparedStatement pst;
    PreparedStatement pst1;
    ResultSet rs;
   

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        try 
        {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/ebank", "root", "");
            String fname = request.getParameter("fname");
            String lname = request.getParameter("lname");
            String address = request.getParameter("address");
            String phone = request.getParameter("phone");
            
            
            pst = con.prepareStatement("insert into registation(fname,lname,address,phone)values(?,?,?,?)");
            pst.setString(1, fname);
            pst.setString(2, lname); 
            pst.setString(3, address);
            pst.setString(4, phone);
            pst.executeUpdate();
            
            pst1 = con.prepareStatement("select max(id) from registation");
            rs = pst1.executeQuery();
            
            rs.next();
            
            int regno;
            
            regno = rs.getInt(1);
            
            out.println("Thank you for your Registation");
            out.println("Your Registaion No is :" + regno);
            
            
        } catch (ClassNotFoundException ex) {
           ex.printStackTrace();
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
    }
}

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 weeks ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

1 month ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

1 month ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

2 months ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

2 months ago