Registration Form Using Servlet in Java


This article explains how to create a registration form in a Servlet. The Netbeans IDE is used for this example.

Registration Form in Servlet

This article explains how to create a simple registration form in a Servlet. In this registration form the following tools are used:

  • Oracle 10g database
  • Tomcat server
  • NetBeans IDE

We need to create the following files:

  1. userlogin table
  2. index.html file
  3. file
  4. web.xml file

1. userlogin table

We need a table to store user information in the database. In this "registration form" we create a table named "userlogin".

Syntax for table:

create table userlogin(name varchar2(4000), password varchar2(4000), emailid varchar2(4000), country varchar2(4000));

Or use the following procedure.

Step 1

Open the database home page and login to your account as in the following:


Step 2

Now click on "Object Browser" and choose "Create" -> "Table" as in the following:.


Step 3

Now type the following details of your table (as table name and their column names) as in the following:


Step 4

Now click on "Next" until you reach the create page, then your table is created as in the following:


Now to create the other files:

  • index.html
  • web.xml

We need to use the following procedure for this.

Step 5

Open the NetBeans IDE.


Step 6

Choose "Java web" -> "Web project" as in the following:


Step 7

Now type your project name as "RegistrationForm" as in the following:


Step 8

Click on "Next" and choose your server wizard; I selected Tomcat7 as in the following:.


Step 9

Now delete your default "index.jsp" file and create a new "index.html" file and write the following code there.


<!DOCTYPE html>



        <title>User Registration Form</title>


    <body bgcolor="pink">

    <center><h1>Registration Form</h1></center><br>

    <form method="post" action="SignUpServlet">







                    <input type="text" name="uname">          




                Create Password:



                <input type="password" name="upass">




                    Confirm Password:



                    <input type="password" name="upass">








                    <input type="text" name="uemailId">








                    <select name="ucountry">

                        <option>India </option>










                    <input type="submit" value="Login">



                    <input type="reset" value="reset">







Step 10

Now create a servlet file with the name "SignUpServlet" and provide the following code for it.


import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;

public class SignUpServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)

            throws ServletException, IOException {


        PrintWriter out = response.getWriter();

        String n = request.getParameter("uname");

        String p = request.getParameter("upass");

        String e = request.getParameter("uemailId");

        String c = request.getParameter("ucountry");

        try {


            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "sandeep", "welcome");

            PreparedStatement stmt = con.prepareStatement("insert into userlogin values(?,?,?,?)");

            stmt.setString(1, n);

            stmt.setString(2, p);

            stmt.setString(3, e);

            stmt.setString(4, c);

            int i = stmt.executeUpdate();

            if (i > 0) {

                out.println("You are successfully registered.....");


        } catch (Exception ey) {






Step 11

Now ensure that the code of your web.xml file is the same as:


<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">










Step 12

Now your project is ready.

Right-click on the project menu then select "Run" as in the following:


The following output is generated.


Now fill in the detail as shown.


Click on "Reset" if you think you would pass some incorrect data. The demo of the reset is shown below. Since here I typed the wrong emailid, now I click on the Reset button.


Fill in the correct detail. I filled in the following details.


Now click on "Finish"; the "SignUpServlet" is showing the following message.



Now your data is saved in the database you created at the beginning of this article.

To see the data in the database,

open the database home page and

go to "Object Browser" -> "View" -> "Table". Select your table as "userlogin". Now click on "data" that is just shown up over the table.