简单的后台验证
后台验证是WEB应用中使用非常广泛的一种应用形式,常用于验证用户登录\后台数据校验等等.
login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
<!--
var xmlHttp ;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") ;
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest() ;
}
}
function checkUser(){
createXMLHttpRequest() ;
var name = document.getElementById("username").value ;
var password = document.getElementById("password").value ;
var url = "login_check.jsp?username="+name+"&password="+password ;
xmlHttp.open("GET",url,true) ;
xmlHttp.onreadystatechange = showResult ;
xmlHttp.send(null) ;
}
function showResult(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var result = xmlHttp.responseText;//在页面上显示返回的结果
document.getElementById("checkResult").innerHTML="<b>"+result+"</b>" ;
}
}
}
//-->
</script>
</head>
<body>
ajax<br>
用户名:<input type="text" id="username"><div id="checkResult"></div><p>
密码:<input type="text" id="password" ><p>
<input type="button" value="检查用户名" onclick="checkUser()"><p>
</body>
</html>
login_check.jsp
<%@ page language="java" contentType="text/html; charset=GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ajax</title>
</head>
<body>
<%
String name = request.getParameter("username") ;
String password = request.getParameter("password") ;
System.out.println("name--->"+name+" password---->"+password);
if(name != null && password != null){
if(name.equals("ajax") && password.equals("ajax")){
out.write("<font color=red>恭喜你!此用户名可用</font>");
}else{
out.write("<font color=red>此用户名已被人占用</font>") ;
}
}
%>
</body>
</html>
posted on 2007-10-13 21:06
Ke 阅读(1160)
评论(0) 编辑 收藏 所属分类:
ajax