Home Tutorial Jsp JSP check email exists or not

 
 

JSP check email exists or not
Posted on: December 15, 2012 at 12:00 AM
Advertisement
In this tutorial, you will learn how to check from the database whether entered email-id exists or not.

JSP check email exists or not

In this tutorial, you will learn how to check from the database whether entered email-id exists or not. The given code accepts the email id from the user and check whether the given email id already exists or not. If it is already exist in database, then show a message 'Already exists'. Otherwise, it will show a message 'You can register now!'.

availability.jsp:

<html>
<head>
<script type="text/javascript">
function check(value){ 
xmlHttp=GetXmlHttpObject()
var url="checkajax.jsp";
url=url+"?email="+value;
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
var showdata = xmlHttp.responseText; 
document.getElementById("mydiv").innerHTML= showdata;
} 
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body>
<form name="form">
Email Id: <input type="text" name="email" id="email" onkeyup="check(this.value);"><font color="red"><div id="mydiv"></div></font>
</form> 

</body>
</html>

checkajax.jsp:


<%@ page import="java.sql.*" %> 
<%
String name = request.getParameter("email").toString();
System.out.println(name);
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from login where email='"+email+"'");
int count=0;
while(rs.next())
{

count++;
}

if(count>0)
{
data="Email-ID already exists!";
}
else
{
data="You can register now!!!!";
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>
Advertisement

Related Tags for JSP check email exists or not:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 15, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com