1.judgeUsername.html页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>judegUsername.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script language="JavaScript" type="text/javascript">
var request = false;
try{
request = new XMLHttpRequest();
}catch(microsoftIE){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(microsoftOldIE){
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(failed){
request = false;
}
}
}
if(!request){
alert("初始化XMLHttpRequest对象失败");
}
function sendUsername(){
var username = document.getElementById("username").value;
if(username!=null && username!=""){
var url = "./judgeUsername.jsp?username="+escape(username);
request.open("get",url,true);
request.onreadystatechange=updatepage;
request.send(null);
}
}
function updatepage(){
if(request.readyState==4){
if(request.status==200){
document.getElementById("reusername").innerHTML = request.responseText;
//document.getDocumentById("reusername").innerText = request.responseText;
}else if(request.status==404){
alert("找不到页面!");
}else{
alert("错误代码:"+request.status);
}
}
}
function clearMessage(){
document.getElementById("reusername").innerHTML = "";
}
</script>
</head>
<body>
<form action="/register.jsp" method="post">
<table align="center">
<caption>guoyongfei为已注册,其他均未注册</caption>
<tr><th>用 户 名:</th><td><input type="text" name="username" id="username" onblur="sendUsername()" onfocus="clearMessage()"/></td><td width="40%" id="reusername"></td></tr>
<tr><th>密 码:</th><td><input type="password" name="password" id="password"/></td><td width="20"></td></tr>
<tr><th>密码确认:</th><td><input type="surePassword" name="surePassword" id="surePassword"/></td><td width="20"></td></tr>
</table>
</body>
</html>
2.judgeUsername.jsp页面:
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String username = request.getParameter("username");
//System.out.println("username:"+username);
if(username.equals("guoyongfei")){
out.println("<font color='red'>用户名已经注册</font>");
}else{
out.println("<font color='green'>用户名可以用</font>");
}
%>
希望大家给推荐下提示信息较好的表示方法.....
posted on 2008-03-12 17:49
Tiger1102 阅读(2643)
评论(6) 编辑 收藏 所属分类:
每日进阶