<%@ page language="java" pageEncoding="GBK"%>
<%
response.setContentType("text/xmlcharset=gbk")
response.setHeader("Cache-Control","no-cache")
String username=request.getParameter("username")
boolean isValid=false
if(username.equals("admin")){
isValid=true
}
if(isValid){
out.println("<content>该用户名已经存在!</content>")
}
else{
out.println("<content>ok</content>")
}
%>
------------------------
html代码
<html>
<head>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="">
<meta http-equiv="description" content="">
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
<script>
var XMLHttpReq=false
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
XMLHttpReq=new XMLHttpRequest()
}
else if(window.ActiveXObject){
try{
XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP")
}catch(e){
try{XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}
}
}
}
function send(url){
//alert(url)
createXMLHttpRequest()
XMLHttpReq.open("GET",url,true)
XMLHttpReq.onreadystatechange=parse
XMLHttpReq.send(null)
}
function parse(){
if(XMLHttpReq.readyState==4){
if(XMLHttpReq.status==200){
var doc = new ActiveXObject("MSxml2.DOMDocument")
doc.loadXML(XMLHttpReq.responseText)
var res=doc.getElementsByTagName("content")[0].firstChild.data
if(res=="ok"){
document.getElementById("status").innerHTML="该用户名可以使用!"
}
else{document.getElementById("status").innerHTML=res
window.alert(res)}
}else{window.alert("所请求的页面异常!")}
}
}
function checkUsername(){
var username=document.getElementById("username").value
if(username==""){
alert("请输入用户名!")
return false
}else{
send('test.jsp?username='+username)
}
}
</script>
</head>
<body bgcolor="#9393FF">
<table height="100%" width="100%">
<tr>
<td align="center">
<table >
<tr>
<td width="10%"></td>
<td>
<form name="form1" >
<table width="300" boder="0">
<tr>
<td colspan="2">
<div id="status"><font size=6>注册新用户</font></div>
</td>
<tr>
<td><font size=5>*用户名</font></td>
<td><input type="text" name="username" size=15 maxlength="10" value="" onblur="checkUsername()" ></td>
</tr>
<tr>
<td><font size=5>*密码</font></td>
<td><input type="password" name="password1" ></td>
</tr>
<tr>
<td><font size=5>*确认密码</font></td>
<td><input type="password" name="password2" ></td>
</tr>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
jsp、和html都做过简单修改,没什么大毛病,需要你细心。 此处的jsp名称换成你自己的send('test.jsp?username='+username)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)