Jspで
<script type="text/javascript">
function VerifyUsername()
{
//alert("In Verify Method");
var name=document.getElementById("username").value;
//alert(name);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
//alert("http");
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
alert("http active");
}
xmlhttp.onreadystatechange=function()
{
//alert("in Function()");
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
try
{
//alert("In Try");
document.getElementById("errorpass").innerHTML=xmlhttp.responseText;
/*var response = xmlhttp.responseText;
alert(response);
if(response.toString()=='notmatch')
{
alert("Ok");
document.getElementById("errorpass").innerHTML ="OK";
}
if(response =='match')
{
alert("Not Ok");
document.getElementById("errorpass").innerHTML ="Take Other Name.";
}*/
}
catch(ex)
{
alert("Exception in function "+ex);
}
}
}
//xmlhttp.open("POST","servlet/UsernamePresence_Serv?UserId"+name,true);
xmlhttp.open("POST","servlet/UsernamePresence_Serv?"+name,true);
var params = "UserId="+name;
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}
</script>
サーブレットで
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try
{
Session session=Hibernate_Class.sessionObject();
String userID=null;
userID = request.getParameter("UserId");
login_model loginModel_Obj=new login_model();
loginModel_Obj._Name=userID;
System.out.print("at "+userID);
boolean username_bool=Hibernate_Class.usernamePresence(loginModel_Obj, session);
if (username_bool)
{
out.println("Username Present In Database");
}
else
{
out.println("Username Not Present In Database");
}
}
finally{}
out.close();
}