js代码:
var xmlHttp=null;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
var name=document.getElementById("name").value;
xmlHttp.open("get","hello.jsp?name="+name,true);
xmlHttp.send(null);
}
function handleStateChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
var st=xmlHttp.responseText;
if(st==1)
{
document.getElementById("aaaa").innerHTML='<img src="images/title_34.gif" width="14" height="14"> <font color="#FF0000">���û��Ѵ���!</font>';
document.all.username.focus();
}
/*alert(xmlHttp.responseText);
if(xmlHttp.responseText=="�û����ظ�!!")
{
alert("�û����ظ�!!");
document.all.username.focus();
}*/
}
}
}
jsp:
<%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*,database.*;" errorPage="" %>
<%
request.setCharacterEncoding("gbk");
String name=request.getParameter("name");
Renameornot r=new Renameornot();
// System.out.print(name);
String s=r.checkname("username",name);
// System.out.print(s);
if(s=="true")
{
out.print("1");
}
else
{
out.print("0");
}
%>