-
<html>
-
<head>
-
<title>这是一个简单登陆验证也可以改为检查用户名是否存在的ajax例子(可以自由扩张)</title>
-
<script type=
"text/javascript"
>
-
var xmlHttpReq;
-
-
function createXMLHttpRequest(){
-
if
(window.ActiveXObject){
-
xmlHttpReq =
new
ActiveXObject(
"MSXML2.XMLHTTP.3.0"
);
-
}
else
{
-
xmlHttpReq =
new
XMLHttpRequest();
-
}
-
}
-
-
function checkUser(){
-
createXMLHttpRequest();
-
var userName =document.getElementById(
"userName"
).value;
-
var password =document.getElementById(
"password"
).value;
-
-
var url=
"checkUser.jsp?userName="
+userName+
"&password="
+password;
-
xmlHttpReq.open(
"GET"
,url,
true
);
-
xmlHttpReq.onreadystatechange = showResult;
-
xmlHttpReq.send();
-
}
-
-
function showResult(){
-
if
(xmlHttpReq.readyState ==
4
){
-
if
(xmlHttpReq.status ==
200
){
-
var result = xmlHttpReq.responseText;
-
-
var checkResult = document.getElementById(
"checkResult"
).innerHTML=
"<b>"
+result+
"</b>"
;
-
-
-
-
-
}
-
}
-
}
-
</script>
-
</head>
-
<body>
-
用户名:<input type=text
" id="
userName"><p>
-
密 码:<input type=text
" id="
password"><p>
-
<input type=
"button"
value=
"提交"
onclick=
"checkUser()"
><p>
-
<div id=
"checkResult"
></div>
-
</body>
-
</html>
-
<%@ page contentType=
"text/html;charset=gb2312"
%>
-
<%
-
String userName=request.getParameter(
"userName"
);
String password=request.getParameter(
"password"
);
System.out.println(
"userName="
+userName);
if
(userName!=
null
&& password!=
null
){
if
(userName.equals(
"huanglq"
) && password.equals(
"password"
)){
out.println(
"<font color='green' >验证成功</font>"
);
}
else
{
out.println(
"<font color='red' >用户名或密码错误</font>"
);
}
}
%>
posted on 2008-04-02 22:55
影子 阅读(193)
评论(0) 编辑 收藏 所属分类:
学习笔记