代码如下:<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%><!--  
String action = request.getParameter("action");
String username = request.getParameter("username");
String password = request.getParameter("password");
if(username == null || !username.equals("user")) {
out.println("username not correct!");
return;
}
if(password == null || password.equals("password")) {
out.println("password not correct!");
return;
}out.println("Welcome!");
--><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>欢迎使用学生选课管理系统</title>

</head>
<body><div align="center">
<div>

<h1>学生选课管理系统</h1>
</div>
<div>
<h2>用户登录/Login</h2>
</div>
<div>
<form name="login" action="LoginDeal.jsp" method="post" onSubmit="Check()">
<label for="">Username:</label> <input type="text" name="username" size="15" value="" /><br />
<br />
<label for="">Password:</label> <input type="password" name="password" size="15" value="" /><br />
<table>
<tr>
<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="Manage" tabindex="4" /><label for="RadioButtonList1_0">部门</label></td><td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Teacher" tabindex="4" /><label for="RadioButtonList1_1">教师</label></td><td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="Student" checked="checked" tabindex="4" /><label for="RadioButtonList1_2">学生</label></td>
</tr>
</table>
<input type="submit" name="submit" value="登录" />
<input type="reset" name="reset" value="重置" />

<script language="JavaScript" type="text/javascript">
function Check() {
if(document.login.username.value == "") {
window.alert("账号不能为空!");
return false;
}
if(document.login.password.value == "") {
window.alert("密码不能为空!");
return false;
}
return true;
}
</script>
</form>
<br>
<div>
</div>
</div></div>
</body>
</html>

解决方案 »

  1.   

    应该这样吧:
    onSubmit="return Check()"
      

  2.   


    这样的话 onSubmit="return Check()" 整条语句都报错,下面是一条红线
    求解
      

  3.   

    Check()放在登录按钮的click事件里试试呢。。
      

  4.   

    可是 return Check() 会报错啊
      

  5.   

    <input type="submit" name="submit" value="登录" onclick="return Check();" />试试。。
      

  6.   

    <script language="JavaScript" type="text/javascript">
    function Check() {
    if(document.login.username.value == "") {
    window.alert("账号不能为空!");
    return false;
    }
    if(document.login.password.value == "") {
    window.alert("密码不能为空!");
    return false;
    }
    [color=#FF0000return true;[/color]
    }
    </script>
    顺序执行后,最后执行return true;了,你说跳转不?
      

  7.   

    onSubmit="return Check();" 这样应该没有问题。
      

  8.   

    <form name="login" id="login" action="" method="post">
    <label for="">Username:</label> <input type="text" name="username" size="15" value="" /><br />
    <br />
    <label for="">Password:</label> <input type="password" name="password" size="15" value="" /><br />
    <table>
    <tr>
    <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="Manage" tabindex="4" /><label for="RadioButtonList1_0">部门</label></td><td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Teacher" tabindex="4" /><label for="RadioButtonList1_1">教师</label></td><td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="Student" checked="checked" tabindex="4" /><label for="RadioButtonList1_2">学生</label></td>
    </tr>
    </table>
    <input type="button" name="button" value="登录" onClick="Check();"/>
    <input type="reset" name="reset" value="重置" /><script language="JavaScript" type="text/javascript">
    function Check() {
    if(document.login.username.value == "") {
    window.alert("账号不能为空!");
    return false;
    }
    if(document.login.password.value == "") {
    window.alert("密码不能为空!");
    return false;
    }
    onSubmit();
    }function onSubmit(){
    document.login.action="LoginDeal.jsp";
    document.login.submit();
    }
    </script>
    </form>
    LZ试试这样行不行
      

  9.   

    使用onSubmit="return Check();"肯定没问题呀
     不要以为jsp页面里,onSubmit="return Check();"这个下面会出现红线就以为是错的!
      

  10.   


    果真是eclipse的问题,两种方法都试过了,都很ok,非常谢谢你!还有楼上的各位,谢谢了!