<script language="javascript">
function isNull(str)
{
if (str.length==0)
return true;
else
return false;
}
function isValidate(form)
{
userid1=form.userid1.value;
userpass=form.userpass.value;
if(isNull(userid1))
{
alert("请输入账号!");
return false;
}
if(isNull(userpass))
{
alert("请输入密码!");
return false;
}
return true;
}
</script>
这部分的代码在登录的时候不起作用,账号密码没填就点击登录,alert内的内容没有弹出来,反而是直接运行了相关的servlet文件,就像请问这要怎么解决?完整的jsp代码在下面
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
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 'loginUser1.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 isNull(str)
{
if (str.length==0)
return true;
else
return false;
}
function isValidate(form)
{
userid1=form.userid1.value;
userpass=form.userpass.value;
if(isNull(userid1))
{
alert("请输入账号!");
return false;
}
if(isNull(userpass))
{
alert("请输入密码!");
return false;
}
return true;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form id="loginUser1" name="loginUser1" method="post" action="UserLoginServlet1" onSubmit="return isValidate(loginUser1)"><br><br>
<p align="center">账 号:
<input type="text" name="userid1" class="ipt-t" />
</p>
<p align="center">密 码:
<input type="password" name="userpass1" class="ipt-t" />
</p>
<p align="center">
<input type="submit" name="submit" value="登录" />
<input type="reset" value="清空" name="reset" />
</form>
</body>
</html>