Skip to content
Related Articles

Related Articles

Servlet – Registration Form

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 04 Mar, 2022

We will need to link your servlet application to a database in order to create a registration form. Here we are using MySQL database. Registration form using Html, Servlet, and MYSQL.

  1. Design registration page using Html.
  2. Create a Database and table in the MYSQL workbench.
  3. Database connectivity in java using JDBC MYSQL.

We can see the flow of the Registration form below diagram as follows: 

Firstly we take input from the user by using the index.html file after this step we send that data to the file which is a servlet file. In Servlet we have connected our Mysql database by using the MySQL jar file. If there is no error in input then data will be inserted into our database table and we will get the message of successful insertion of data.  


Creating a Table in Database

create table GfgLogin
   name varchar(60),
   email varchar(60),
   pass varchar(100)

A. File: web.xml


<web-app  version="3.0"



B. File:



import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class GfgRegister extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String name = request.getParameter("name");
        String email = request.getParameter("email");
        String pass = request.getParameter("pass");
        try {
            // loading drivers for mysql
            //creating connection with the database
            Connection con = DriverManager.getConnection
            PreparedStatement ps = con.prepareStatement
                        ("insert into gfglogin values(?,?,?)");
            ps.setString(1, name);
            ps.setString(2, email);
            ps.setString(3, pass);
            int i = ps.executeUpdate();
            if(i > 0) {
                out.println("You are successfully registered at geeksforgeeks");
        catch(Exception se) {



C. File: index.html



        <title>GeeksForGeeks Register form</title>
        <form method="post" action="GfgRegister">
        Name:<input type="text" name="name" /><br/><br/>
        Email ID:<input type="text" name="email" /><br/><br/>
        Password:<input type="text" name="pass" /><br/><br/>
        <input type="submit" value="GfgRegister" /><br/>



Output: Run your index.html file, you will get the following output:



After you’ve entered your information and clicked the register button, you’ll see the screen below.



Data stored in the database is as shown below in below media as follows: 



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!