JSP登录时判断账号密码不能为空

希望能从这个代码里修改
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登录界面</title>
</head>
<body>
<center>
<h1>
欢迎光临!
</h1>
</center>
<form name="form1" method="post" action="Verification.jsp"onsubmit="return userCheck()">
<table width="30%" height="144" border="0" align="center">
<tr>
<td width="19%">
用户名:
</td>
<td width="81%">
<label for="id"></label>
<input name="id" type="text" id="id" size="25"
maxlength="30" />
</td>
</tr>
<tr>
<td>
密码:
</td>
<td>
<label for="password"></label>
<input name="password" type="password" id="password" size="25"
maxlength="30" />
</td>
</tr>
<tr>
<td>

</td>
<td>
<input type="submit" name="button" id="button" value="登录" />
<input type="button" value="注册" onClick="window.location.href='login.jsp'">
</td>
</tr>
<tr>
<td>

</td>
<td>

</td>
</tr>
</table>
</form>
</body>
<script language="javascript">
function check_login()
{
if(document.form1.username.value==''")/*document.表单名.文本域名.value==''"*/
{
alert("请检查用户名是否为空!");
return false;
}
if(document.form1.password.value==''"){
alert("请检查您的密码是否为空!");
return false
}
if(document.form1.password.value.length<6){
alert("您的密码长度小于6!");
return false
}
}
</script>
</html>

onsubmit="return userCheck()"

你自己是这样写的,所以js中要有验证函数userCheck;
function userCheck()
{
if(document.form1.username.value==''")/*document.表单名.文本域名.value==''"*/
{
alert("请检查用户名是否为空!");
return false;
}
if(document.form1.password.value==''"){
alert("请检查您的密码是否为空!");
return false
}
if(document.form1.password.value.length<6){
alert("您的密码长度小于6!");
return false
}
}追问

试了不行,还是直接跳转到失败的页面没有提示,是不是我登录的那个连接有问题

追答

userCheck方法没有执行吗

追问

没有,我按登录时直接跳转到Verification.jsp

追答

onsubmit="return userCheck()">

改为
onsubmit="return userCheck();return false;">

试试

追问


onsubmit="return userCheck();return false;">
function userCheck()
{
if(document.form1.username.value==''")/*document.表单名.文本域名.value==''"*/
{
看一下有没有改错?

追答

靠,你用户名的id不是username啊

追问

该怎么改?

追答



改成

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网