JSP Registration Form

Hi frnds, here I am going to represent a registration form in JSP. For creating registration form, we must have a table in the database. You can write the database logic in JSP file.

REGISTRATION STRUCTURE
Required Files:

 

  1. Registration.jsp
  2. RegistrationProcess.jsp

Example of Registration Form in JSP

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

create table register(
id number(10),
name varchar2(45),
mobno number(10),
email varchar2(45),
password varchar2(45),
PRIMARY KEY(id)
);

We have created the table named register here.

Registration.jsp

<html>
<head>
<script>
function validateForm(){
var password=document.myform.password.value;
var email=document.myform.email.value;
var password = document.myform.password.value;
var mobile = document.myform.mobile.value;
if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/).test(document.myform.email.value))
{
alert("You have entered an invalid email address!") ;
return false;
}
else if(mobile.length != 10){
alert("ph no should be 10 digit.");
return false;
}
if(isNaN(mobile))
{
alert("Enter the valid Mobile Number(Like : 9566137117)");
document.myform.mobile.focus();
return false;
}
}
<body style="background-color:#12F6DA " >
<form name="myform" method="post" action="RegistrationProcess.jsp" onSubmit="return validateForm();">
<center>
<table border="1" width="50%" cellpadding="5">
<thead>
<tr>
<th colspan="2"><h2><font color="#9209DB">Registration Form</font></h2>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>User ID</td>
<td><input type="text" name="id" value="   " required/></td>
</tr>
<td>Name</td>
<td><input type="text" name="name" value="   " required/></td>
</tr>
<td>Mobile No</td>
<td><input type="text" name="mobno" value="   " required/></td>
</tr>
<td>Email</td>
<td><input type="text" name="email" value="   " required/></td>
</tr>
<td>password</td>
<td><input type="text" name="password" value="   " required/></td>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" value="Submit" /><td>
</tr>
<tr>
<td colspan="2">Already registered? <a href="slogin.jsp">Login Here</a> </td>
</tr>
</tbody>
</table>
</center>
</form>
</fieldset>
</html>
</div>
</div>



RegistrationProcess.jsp

<%@ page import ="java.sql.*" %>
<body>
<%
String s1 = request.getParameter("id");
String s2 = request.getParameter("name");
String s3 = request.getParameter("mobno");
String s4 = request.getParameter("email");
String s5 = request.getParameter("password");
int k=0;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = null;
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "bikash");
PreparedStatement ps=con.prepareStatement("insert into register values(?,?,?,?,?)");

ps.setString(1,s1);
ps.setString(2,s2);
ps.setString(3,s3);
ps.setString(4,s4);
ps.setString(5,s5);

k=ps.executeUpdate();
if (k > 0) {
out.println("Register Successful");
}
else{
out.println("Error! Try Again");
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>

Output


REGISTRATION FORM

REGISTRATION SUCCESS

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment