AJAX JSP
<%@ page import="java.sql.*" %>
<%
String email = request.getParameter("email").toString();
System.out.println(email);
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "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="<img src='favicon.png' width='20px' height='20px'>Email-ID already exists!";
}
else
{
data="You can register now!!!!";
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>
<html>
<head>
<script type="text/javascript">
function check(value){
xmlHttp=GetXmlHttpObject()
var url="index.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>
<marquee>Hello</marquee>
<form name="form">
Email Id: <input type="text" name="email" id="email" onkeyup="check(this.value);">
<div id="mydiv"></div>
</form>
</body>
</html>
<%
String email = request.getParameter("email").toString();
System.out.println(email);
String data ="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test1", "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="<img src='favicon.png' width='20px' height='20px'>Email-ID already exists!";
}
else
{
data="You can register now!!!!";
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>
<html>
<head>
<script type="text/javascript">
function check(value){
xmlHttp=GetXmlHttpObject()
var url="index.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>
<marquee>Hello</marquee>
<form name="form">
Email Id: <input type="text" name="email" id="email" onkeyup="check(this.value);">
<div id="mydiv"></div>
</form>
</body>
</html>
Comments
Post a Comment