求jsp高手帮忙,我要实现的是一个用户登录界面,用了JavaScript来进行相关的验证,如用户名不能为空,但在浏览器不能实现相关的验证功能,求高手,下面是我的代码,
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title><style type="text/css">
<!--
.STYLE1 {font-size: 24px}
-->
</style><script language="javascript">
function check()
{ var x=document.getElementById("username").value;
var y= document.getElementById("password").value;
if(x==""&&x===null){alert("请输入用户名")
document.getElementById("username").focus();
return false;}
if(y==""&&y===null){alert("请输入密码")
document.getElementById("password").focus();
return false;}
}</script>
</head><body>
<form id="form1" name="form1" method="post" action="" onsubmit="javascript:return check()" >
<table width="221" border="0" align="center" bgcolor="#00FF00">
<tr>
<td width="211" height="17" align="center"><span class="STYLE1">用户登录</span></td>
</tr>
<tr>
<td height="25" nowrap="nowrap"><span class="STYLE1">用户名:</span>
<input name="username" type="text" size="23" /></td>
</tr>
<tr>
<td height="30"><span class="STYLE1">密 码:</span>
<input name="password" type="password" size="23" /></td>
</tr>
<tr>
<td height="17" align="center"><input type="submit" name="Submit" value="登录" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
<tr>
<td height="26"> </td>
</tr>
</table>
</form>
</body>
</html>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title><style type="text/css">
<!--
.STYLE1 {font-size: 24px}
-->
</style><script language="javascript">
function check()
{ var x=document.getElementById("username").value;
var y= document.getElementById("password").value;
if(x==""&&x===null){alert("请输入用户名")
document.getElementById("username").focus();
return false;}
if(y==""&&y===null){alert("请输入密码")
document.getElementById("password").focus();
return false;}
}</script>
</head><body>
<form id="form1" name="form1" method="post" action="" onsubmit="javascript:return check()" >
<table width="221" border="0" align="center" bgcolor="#00FF00">
<tr>
<td width="211" height="17" align="center"><span class="STYLE1">用户登录</span></td>
</tr>
<tr>
<td height="25" nowrap="nowrap"><span class="STYLE1">用户名:</span>
<input name="username" type="text" size="23" /></td>
</tr>
<tr>
<td height="30"><span class="STYLE1">密 码:</span>
<input name="password" type="password" size="23" /></td>
</tr>
<tr>
<td height="17" align="center"><input type="submit" name="Submit" value="登录" />
<input type="reset" name="Submit2" value="重置" /></td>
</tr>
<tr>
<td height="26"> </td>
</tr>
</table>
</form>
</body>
</html>
<input name="password" id="password" type="password" size="23" />
首先