.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Registration page in jsp

Posted By:satyapriyanayak       Posted Date: September 16, 2014    Points: 200    Category: General    URL: http://www.dotnetspark.com  

In this article we will know how to a simple registration page using Java Server Page.
 

Before doing this we should have some knowledge about jdbc
This is a technology to establish communication between java program and a DBMS.It uses SQL (structure query language) for storing, updating, or removing data from a DBMS .The java program can be stand alone application, web application or enterprise application

Steps to follow for connecting to DBMS
1.Load the driver class into runtime environment by using forName() method of java.lang class.This method accepts a string parameter to contain the class name.This method throws java.lang class not found exception. Class is a predefined class and forName is the static method of the class, which is used to load the driver in the memory for connectivity.
Ex:- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")

2.Create a reference of java.sql.connection by using getConnection() method of java.sql. DriverManager class.This method access three parameters as path of the driver in JDBC:ODBC bridge.We required DSN(Data source name) in this position.Dsn can be created in control panel

Ex: Connection con=DriverManager.getConnection("jdbc:odbc:dsnname","system","password");

The getConnection() method throws java.sql.sql exception.

3.Create an object of java.sql statement by using create statement () method of connection. Statement is being used to execute various sql commands.
Ex:- Statement stmt=con.createStatement();

4.Use appropriate method of statement to execute sql command for select command use executeQuery() method and for insert, update and delete use executeUpdate() method.

What is DSN?
This is a name provided to DBMS driver present in ODBC.This recognizes the database to be used of a specific DBMS.

Creation of dsn(database source name) for Oracle
 
Start-Control panel- Administrative Tools- Data Sources (ODBC)-go to system dsn tab-click add button-select a driver for which you want to set up data source (for Oracle- Oracle in XE)-select it and click finish-give any name in data source name textbox-then click ok button.

Note:- Here Username=system, Password=pintu and Dsn name=dsn1

In this registration we use css, java script for validation of blank form, confirm password and email validation. Here we use a html page where user can enter there details and after submitting the button action goes to the doRegister.jsp page where data is being saved in the database and the register user name is shown as output in success.jsp page.

Table creation
create table employee(name varchar(50),pass varchar(50),cpass varchar(50),email varchar(50),phone int,fax int,city varchar(50),state varchar(50),zip varchar(50))

Account.html page

<html>
<head>
<title>Untitled Page</title>
<link href="./STYLE.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.deepbluetextbold {  font: Bold 10pt Verdana, Helvetica, sans-serif; color: #006db9;}
.colouredCell { background-color: #eeeeee;}
</style>
<script language="javascript">
function validate(objForm){
if(objForm.t1.value.length==0){
alert("Please enter Name!");
objForm.t1.focus();
return false;
}

if(!(isNaN(document.objForm.t1.value)))
{
alert("Name has character only!");
return false;
}

if(objForm.t2.value.length==0){
alert("Please enter Password!");
objForm.t2.focus();
return false;
}

if(objForm.t3.value.length==0){
alert("Please enter Confirm password!");
objForm.t3.focus();
return false;
}

if(document.getElementById("t2").value!=document.getElementById("t3").value)
{
alert("Confirm Password doesnot match!");
document.getElementById("t3").focus();
return false;
}

if(objForm.t4.value.length==0){
alert("Please enter Email!");
objForm.t4.focus();
return false;
}

if (document.objForm.t4.value != "")
{
var Temp     = document.objForm.t4
var AtSym    = Temp.value.indexOf('@')
var Period   = Temp.value.lastIndexOf('.')
var Space    = Temp.value.indexOf(' ')
var Length   = Temp.value.length - 1
if ((AtSym < 1) ||
(Period <= AtSym+1) ||
(Period == Length ) ||
(Space  != -1))
{
alert("Please enter a valid Email ID!");
document.objForm.t4.focus();
return false;
}
}

if(objForm.t5.value.length==0){
alert("Please enter Phone!");
objForm.t5.focus();
return false;
}

if(objForm.t6.value.length==0){
alert("Please enter Fax!");
objForm.t6.focus();
return false;
}

if(objForm.t7.value.length==0){
alert("Please enter City!");
objForm.t7.focus();
return false;
}

if(!(isNaN(document.objForm.t7.value)))
{
alert("City has character only!");
objForm.t7.focus();
return false;
}

if(objForm.t8.value.length==0){
alert("Please enter State!");
objForm.t8.focus();
return false;
}

if(!(isNaN(document.objForm.t8.value)))
{
alert("State has character only!");
objForm.t8.focus();
return false;
}

if(objForm.t9.value.length==0){
alert("Please enter Zip!");
objForm.t9.focus();
return false;
}

return true;
}
</script>
</head>
<body >
<form name ="objForm" action="./doRegister.jsp" method="post" onSubmit="return validate(this)">
<table>
<tr>
        <td class="deepbluetextbold"><b>Create a user account</b></td>
        </tr>
        <tr>
        <td class="colouredCell"><b>Name*</b></td>
            <td><input name="t1" type="text " /></td>
        </tr>
        <tr>
         <td class="colouredCell"><b>Password*</b></td>
            <td><input name="t2" type="password" /></td>
        </tr>
     <tr>
         <td class="colouredCell"><b>Confirm password*</b></td>
            <td><input name="t3" type="password" /></td>
        </tr>
     <tr>
         <td class="colouredCell"><b>Email*</b></td>
            <td><input name="t4" type="text" /></td>
        </tr>
     <tr>
         <td class="colouredCell"><b>Phone*</b></td>
            <td><input name="t5" type="text" /></td>
        </tr>
     <tr>
         <td class="colouredCell"><b>Fax*</b></td>
            <td><input name="t6" type="text" /></td>
        </tr>

        <tr>
                 <td class="colouredCell"><b>City*</b></td>
                    <td><input name="t7" type="text" /></td>
        </tr>
        <tr>
                 <td class="colouredCell"><b>State*</b></td>
                    <td><input name="t8" type="text" /></td>
        </tr>
        <tr>
                 <td class="colouredCell"><b>Zip*</b></td>
                    <td><input name="t9" type="text" /></td>
        </tr>
    </table>
     <input type="submit" value="Register"/>
</form>
</body>
</html>

doRegister.jsp

<%@ page import="java.sql.*" %>
<%
String str1=request.getParameter("t1");
String str2=request.getParameter("t2");
String str3=request.getParameter("t3");
String str4=request.getParameter("t4");
String str5=request.getParameter("t5");
String str6=request.getParameter("t6");
String str7=request.getParameter("t7");
String str8=request.getParameter("t8");
String str9=request.getParameter("t9");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dsn1","system","pintu");
PreparedStatement pstmt=con.prepareStatement("insert into employee(name,pass,cpass,email,phone,fax,city,state,zip) values(?,?,?,?,?,?,?,?,?)");
pstmt.setString(1,str1);
pstmt.setString(2,str2);
pstmt.setString(3,str3);
pstmt.setString(4,str4);
pstmt.setString(5,str5);
pstmt.setString(6,str6);
pstmt.setString(7,str7);
pstmt.setString(8,str8);
pstmt.setString(9,str9);
pstmt.executeUpdate();
con.close();
 %>
<jsp:forward page="/success.jsp">
<jsp:param name="reg" value="<%= str1 %>" />
</jsp:forward>

success.jsp

<html>
<body>
<%
  String str1=request.getParameter("t1");
%>
<h4><font color='Red'>Welcome:::</font><b><font color='#663300'><%= str1 %></font></b></h4>
</body>
</html>

Running the application

http://localhost:8081/jsp/


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend