前端判断
登陆页面输入是否符合要求
<script type&#61;"text/Javascript" src&#61;"js/login.js">script>
<script language&#61;"Javascript">
function rec(){
alert("欢迎登入家庭管理系统");
}
script>
<h2>新成员&#xff1a;<a href&#61;"${pageContext.request.contextPath}/register">注册a>h2>
${pageContext.request.contextPath}
取得绝对路径
-->
<form name&#61;"f1" id&#61;"f1" action&#61;"login" method&#61;"post" onsubmit&#61;"return check()">
<table border&#61;"0" width&#61;"250px" height&#61;"150px">
<tr>
<td>账号:td>
<td><input type&#61;"text" name&#61;"username" id&#61;"username"/>td>
tr>
<tr>
<td>密码:td>
<td><input type&#61;"password" name&#61;"password" id&#61;"password"/>
td>
tr>
<tr >
<td colspan&#61;"2"><input type&#61;"checkbox" name&#61;"remPwd" id&#61;"remPwd"/>记住密码td>
tr>
<tr>
<td align&#61;"right"><input type&#61;"submit" onclick &#61; "rec()"value&#61;"登录"/> td>
<td align&#61;"center"> <input type &#61; "reset" value &#61; "重置" >td>
tr>
<tr>
<td colspan&#61;"2" align&#61;"center" >
<jsp:useBean id&#61;"time" type&#61;"java.io.Serializable" beanName&#61;"java.util.Date"/>
<hr>登入时间&#xff1a;<%&#61;time %><hr>
td>
tr>
<tr>
<td colspan&#61;"2" align&#61;"center" class&#61;"msg_error" id&#61;"msg" >
<div id &#61; "msg">
${msg}
div>
td>
tr>
table>
form>
注意:
<jsp:useBean id&#61;"time" type&#61;"java.io.Serializable" beanName&#61;"java.util.Date"/>
<hr>登入时间&#xff1a;<%&#61;time %><hr>
当前登入时间
login.js页面:
function check(){
var msg&#61;document.getElementById("msg");
var e_username&#61;document.getElementById("username");
var e_password&#61;document.getElementById("password");
var username&#61;e_username.value;
var password&#61;e_password.value;
if(username&#61;&#61;null || username&#61;&#61;""){
//账号不能为空
msg.innerHTML&#61;"账号不能为空";
e_username.style.border&#61;"solid 1px #f00";
return false;
}
if(password&#61;&#61;null || password&#61;&#61;""){
msg.innerHTML&#61;"密码不能为空";
e_password.style.border&#61;"solid 1px #f00";
retur
n false;
}
if(username.length<3 || username.length>7){
//账号长度不合法
msg.innerHTML&#61;"账号长度不合法&#xff08;3~7内&#xff09;";
e_username.style.border&#61;"solid 1px #f00";
return false;
}
if(password.length<2 || password.length>20){
//密码长度不合法
msg.innerHTML&#61;"密码长度不合法&#xff08;2~20内&#xff09;";
e_password.style.border&#61;"solid 1px #f00";
return false;
}
return true;
}