日期:2014-05-16 浏览次数:20481 次
采用JS实现用户登录的判断(没有链接数据库),js代码如下(js代码是放在WebRoot下的js文件夹下的login.js中):
function check(form){
if(form.user.value.length<6||form.user.value.length>12){
alert("用户名长度有错!")
}else{
if(form.password.value.length<6||form.password.value.length>12){
alert("密码长度有错!")
}else{
if(form.user.value=="123456"&&form.password.value=="123456"){
alert("登陆成功!")
}else{
alert("登录失败,用户名或密码出错!")
}
}
}
}
?jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>Login-登录</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 charset="gb2312" src="js/login.js">
</script>
</head>
<body>
<form action="" method="post" name="form" onsubmit="return check(form)">
<table align="center">
<tr>
<td>
用户:
</td>
<td>
<input type="text" name="user" >
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<input type="password" name="password" >
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
?