(2)如果不存在数组中存在表单提交的客户信息,说明该用户身份非法,调用非法用户提示页面。
<html>
<head>
<script language="JavaScript">
function Verify()
{
var pwd=document.Form.userpwd.value;
if (isNaN(parseInt(pwd)))
{
alert("必须是数字!");
return false;
}
else if ((pwd.length!=10))
{
alert("必须输入10位!");
return false;
}
else
{
return true;
}
}
</script></head>
<body>请输入:<br>
<form name="Form" onSubmit="return Verify();" method="post" action="aaa.jsp">
姓名:<input type="text" name="userid" value=""><br>
密码:<input type="password" name="userpwd" value=""><br>
<input type="submit" value="提交" width=100>
<input type="reset" value="重置" width=100></form>
</body></html>
aaa.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="Errorpage.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<%
request.setCharacterEncoding("GBK");
String Username="";
String Userpwd="";
Username =(String) request.getParameter("userid");
Userpwd =(String) request.getParameter("userpwd");
String id[]=new String[5],pwd[]=new String[5];
id[1]="llx"; pwd[1]="1234567890";
id[2]="kf"; pwd[2]="0123456789";
id[3]="lb"; pwd[3]="0987654321";
id[4]="laoshi"; pwd[4]="9876543210";
id[0]="dd"; pwd[0]="1231231231";
for(int i=0;i<5;i++)
{
if(Username.trim().equals(id[i])&&Userpwd.trim().equals(pwd[i]))
response.sendRedirect("http://www.baidu.com");
else response.sendRedirect("Errorpage.jsp");
}
%>
</html>
Errorpage.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" isErrorPage="TRUE" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<%
out.print("用户名或密码错误! 请返回重新操作!");
%>
</html>