<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'userValidate.jsp' starting page</title>
<script type="text/javascript">
function validate(){
var username = form1.username.value
var password = form1.password.value
if(username.trim().length==0){
alert("用户名不能为空!")
form1.username.focus()
}else if(password.trim().length==0){
alert("密码不能为空!")
form1.password.focus()
}
}
</script>
</head>
<body>
<form action="#" name="form1" onsubmit="return validate(this);">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密 码:</td>
<td>
<input type="password" name="password"/>
</td>
</tr>
<tr><td><input type="submit" value="提交" ></td></tr>
</table>
</form>
</body>
</html>