❮ Previous Next ❯

Registration form example in Servlet

In this example you will see how to develop a registration form in Servlet. To develop a registration form you will need to connect your servlet application with database. That means we will implement JDBC in servlet. Here we are using Oracle10g database.

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

We need to create the Required files:

  1. registration table
  2. reg.html file
  3. MyServlet.java file
  4. web.xml file

step-1: Create a table in database

create table registration
name varchar2(100),
email varchar2(100),
password varchar(100),
country varchar2(100)

Step-2: reg.html

<!DOCTYPE html>
<title>Registration Form</title>
<body bgcolor="pink">
<center><h1>Registration Form</h1></center><br>
<form action="MyServlet"method=”post”>
<input type="text" name="uname">
Create Password:
<input type="password" name="pwd">
Confirm Password:
<input type="password" name="pwd">
<input type="text" name="email">
< td>
<select name="ucountry">
<option>India </option>
<input type="submit" value="register">
<input type="reset" value="reset">

Step-3: MyServlet.java

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

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class MyServlet 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("pwd");
String e = request.getParameter("email");
String c = request.getParameter("ucountry");
try {
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle");
PreparedStatement stmt = con.prepareStatement("insert into registration values(?,?,?,?)");
stmt.setString(1, n);
stmt.setString(2, p);
stmt.setString(3, e);
stmt.setString(4, c);
int k = stmt.executeUpdate();
if (k > 0) {
out.println("You are successfully registered");
} catch (Exception e) {


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
❮ Previous Next ❯

Follow Us


Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Email: info@silantechnology.com
      Phone: 0674-2361252
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved