Registration Form in JSP by R4R Team

Registration Form in JSP:

For creating registration form, you must have a table in the database. You can write the database logic in JSP file, but separating it from the JSP page is better approach. Here, we are going to use DAO, Factory Method, DTO and Singletion design patterns. There are many files:

index.jsp: for getting the values from the user a bean class that have properties and setter and getter methods.
process.jsp: a jsp file that processes the request and calls the methods an interface that contains many constants like DRIVER_CLASS, CONNECTION_URL, USERNAME and PASSWORD a class that returns an object of Connection. It uses the Singleton and factory method design pattern. a DAO class that is responsible to get access to the database
Example of Registration Form in JSP

In this example, we are using the Oracle10g database to connect with the database. Let's first create the table in the Oracle database:

( "NAME" VARCHAR2(3000),

We have created the table named user56 here.


We are having only three fields here, to make the concept clear and simplify the flow of the application. You can have other fields also like country, hobby etc. according to your requirement.

<form action="process.jsp">

<input type="text" name="uname" value="Name..." onclick="this.value=''"/><br/>

<input type="text" name="uemail" value="Email ID..." onclick="this.value=''"/><br/>

<input type="password" name="upass" value="Password..." onclick="this.value=''"/><br/>

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



This jsp file contains all the incoming values to an object of bean class which is passed as an argument in the register method of the RegisterDao class.

<%@page import="bean.RegisterDao"%>

<jsp:useBean id="obj" class="bean.User"/>

<jsp:setProperty property="*" name="obj"/>


int status=RegisterDao.register(obj);


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

It is the bean class that have 3 properties uname, uemail and upass with its setter and getter methods.

package bean;

public class User {

private String uname,upass,uemail;

public String getUname() {

return uname;


public void setUname(String uname) {

this.uname = uname;


public String getUpass() {

return upass;


public void setUpass(String upass) {

this.upass = upass;


public String getUemail() {

return uemail;


public void setUemail(String uemail) {

this.uemail = uemail;

} }

This interface contains four constants that can vary from database to database.

package bean;

public interface Provider {

String DRIVER="oracle.jdbc.driver.OracleDriver";

String CONNECTION_URL="jdbc:oracle:thin:@localhost:1521:xe";

String USERNAME="system";

String PASSWORD="oracle";


This class is responsible to return the object of Connection. Here, driver class is loaded only once and connection object gets memory only once.

package bean;

import java.sql.*;

import static bean.Provider.*;

public class ConnectionProvider {

private static Connection con=null;





}catch(Exception e){}


public static Connection getCon(){

return con;


This class inserts the values of the bean component into the database.

package bean;

import java.sql.*;

public class RegisterDao {

public static int register(User u){

int status=0;


Connection con=ConnectionProvider.getCon();

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





}catch(Exception e){}

return status; }}

Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!