<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</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="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script language="javascript">
function checkUser(userName){
if(userName.value==""){
alert("请输入用户名");userName.focus();return;
}else{
createRequest('checkuser.jsp?user='+userName.value);
}
}
function createRequest(url){
http_request = false;
if(window.XMLHttpRequest){
http_request = new XMLHttpRequest();
}else if(window.ActiveXObject){
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP"); //创建XMLHttpRequest对象
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP"); //创建XMLHttpRequest对象
} catch (e) {}
}
}
if(!http_request){
alert("不能创建XMLHttpRequest对象");
return false;
}
http_request.onreadystatechange = getResult;
http_request.open('post',url,true);
http_request.send(null);
}
function getResult(){
if(http_request.readyState ==4){
if(http_request.status ==200){
alert(http_request.responseText);
}
else{
alert("你请求的页面有错误");
}
}
}
</script>
</head>
<body>
<tr>
<form name="form1" method="post" action="">
<table width="402" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#777777" bgcolor="#999999">
<tr>
<td height="30" colspan="2" bgcolor="#EEEEEE">·用户注册</td>
</tr>
<tr>
<td width="113" height="30" align="center" bgcolor="#FFFFFF">用 户 名:</td>
<td width="387" bgcolor="#FFFFFF"><input name="username" type="text" id="username" size="30">
<input name="b_checkUser" type="button" class="btn_grey" id="b_checkUser" value="检测用户名" onClick="checkUser(this.form.username);"></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#FFFFFF">密 码:</td>
<td bgcolor="#FFFFFF"><input name="pwd" type="password" id="pwd" size="30"></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#FFFFFF">确认密码:</td>
<td bgcolor="#FFFFFF"><input name="pwd1" type="password" id="pwd1" size="30"></td>
</tr>
<tr>
<td height="40" colspan="2" align="center" bgcolor="#FFFFFF"><input name="b_submit" type="submit" class="btn_grey" id="b_submit" value="提交">
<input name="b_reset" type="reset" class="btn_grey" id="b_reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="GBK" %>
<%
String[] userList={"明日科技","mr","wgh","mrsoft"};
String user=new String(request.getParameter("user").getBytes("ISO-8859-1"),"GBK"); //获取用户名
out.println(user);
Arrays.sort(userList); //对数组排序
int result=Arrays.binarySearch(userList,user); //搜索数组
if(result>-1){
out.println("很抱歉,该用户名已经被注册!"); //输出检测结果
}else{
out.println("恭喜您,该用户名没有被注册!"); //输出检测结果
}
%>
此外,javascript在html代码中不分大小写,,arrays找不到返回-1