try this : call a js method in your jsp file in text field like :-
and in your js file use these methods.
var req;
function initRequest(url) {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
initRequest(url);
req.onreadystatechange = processRequest;
req.open("POST", url, true);
req.send(null);
}
}
function checkUser() {
var val = document.forms["formName"].u_name.value;
if(val == null || val == "") {
} else {
var url = "checkUser.jsp?uname=" + val;
initRequest(url);
req.onreadystatechange = processRequest;
req.open("POST", url, true);
req.send(null);
}
}
function processRequest() {
//alert(req.readyState);
if (req.readyState == 4) {
document.getElementById("usercheck").innerHTML=req.responseText;
}
}
and now make a page as checkUser.jsp on which you can get parameter value of uname sent throug js and chekc this in your method using db queries.
create a div element with an id usercheck that will display the processed result from tha last js method i have shown, to whatever you want to display ,show that using your checkuser.jsp
checkuser.jsp
String user_Name = request.getParameter("uname");
response.setContentType("text/html;charset=UTF-8");
PrintWriter pen = response.getWriter();
try {
result = ins.populate(user_Name);
} catch (Exception e) {
}
if(result == true) {
pen.write("<img alt='Available' src='/images/Active.png'>Not Available");
} else {
pen.write("<img alt='Available' src='/images/Deactive.png'>Available");
}
%>
this will show the result returned on your page a available and not avialble