Example Of Registration Form In Servlet


Today We will study how to make a Simple Registration form in Servlet. We are going to use the Oracle 10g Database. Firstly we need to create a table as given below:

   (    "NAME" VARCHAR2(4000),   
    "PASS" VARCHAR2(4000),   
    "EMAIL" VARCHAR2(4000),   
    "COUNTRY" VARCHAR2(4000)  

To make the registration page in servlet, we are up to separate the database logic from the servlet. But here, we're blending the database logic withinside the servlet best for simplicity of the program. We will expand this web page in JSP following DAO, DTO and Singleton layout samples later.

Registration Form in Servlet- Example

We have created 3 pages in this Example:

  • register.html
  • Register.java
  • web.xml


In this page, we have acquired input from the user using text field and combo box. The details entered by the user are sent on to Register Servlet, which is responsible to stock the data into the database.

<form action="servlet/Register" method="post">    

Name:<input type="text" name="userName"/><br/><br/>  
Password:<input type="password" name="userPass"/><br/><br/>  
Email Id:<input type="text" name="userEmail"/><br/><br/>  
<select name="userCountry">  


<input type="submit" value="register"/>    



This Servlet class receives all the data entered by the user and stocks it into the database. Here, we are Performing the database logic. But you can separate it which will be better for the web application.

import java.io.*;  
import java.sql.*;  
import javax.servlet.ServletException;  
import javax.servlet.http.*;  

public class Register extends HttpServlet {  
public void doPost(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {    

PrintWriter out = response.getWriter();           

String n=request.getParameter("userName");  
String p=request.getParameter("userPass");  
String e=request.getParameter("userEmail");  
String c=request.getParameter("userCountry");  

Connection con=DriverManager.getConnection(  

PreparedStatement ps=con.prepareStatement(  
"insert into registeruser values(?,?,?,?)");   

int i=ps.executeUpdate();  
out.print("You are successfully registered...");  
}catch (Exception e2) {System.out.println(e2);}  

Web.xml file

This is the configuration file providing t6he information about Servlet.





download this example

download the war file

download this example (developed using Myeclipse IDE)

download this example (developed using Eclipse IDE)

download this example (developed using Netbeans IDE)

To Connect java application with the oracle database ojdbc14.jar file is essential to be loaded. Put this jar file in WEB-INF/lib folder.

download the jar file ojdbc14.jar´╗┐