表达认证没有起到作用  问题出在哪?  高人指点
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%><html>
<head>
<title>My JSP 'regist.jsp' starting page</title> <script language="JavaScript">function checked(form) { var username = form.username.value;
var password = form.password.value;
if( username==""){
  alert("输入用户名");
  return false;
  }
  
   if( password==""){
  alert("输入密码");
  return   false ;}
  
  
  return true;
  
  
  }
 
  </script>
</head> <body>
<h1>
sad
</h1>
<form name="form1" action="regist.jsp" method="post"
onsubmit="return checked(this) "> <input type="text" name="username" size="28"></input> <input type="password" name="password" size="28"></input> <input type="radio" name="sex" value="nan">
<input type="radio" name="sex" value=" nv">
<p>
<input type=submit name="submit" value="提交">
<input type=reset value="重置">
</p>

</form> </body>
</html>

解决方案 »

  1.   

    呵呵!你有点粗心大意了.
    问题粗心在你的 你用了中文输入法,把 ");" 写成 ”);“ 这样子了. "alert("输入用户名");"  你这句有问题,你改一下你的后面的分号和括号.  
      alert("输入用户名");
      

  2.   

    鉴于1楼的回复,请楼主参考下,下面的表单验证..<%@ page contentType="text/html;charset=GB18030"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
    <%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
    <title>添加家庭成员</title>
    <script language="JavaScript" type="text/JavaScript">
    function checkData()
    {
    theForm = document.modifyform;
    if ( theForm.name.value=="" )
    {
    document.getElementById("name_info").innerHTML = "姓名不能为空";
    document.getElementById("name_info").className = "ErrorMsg";
    theForm.name.focus();
    return(false);
    }
    else if ( theForm.age.value=="" )
    {
    document.getElementById("name_info").innerHTML = "年龄不能为空";
    document.getElementById("name_info").className = "ErrorMsg";
    theForm.age.focus();
    return(false);
    }
    else if ( theForm.password.value=="" )
    {
    document.getElementById("name_info").innerHTML = "成员密码不能为空";
    document.getElementById("name_info").className = "ErrorMsg";
    theForm.password.focus();
    return(false);
    }
    return(true);
    }
    </script>

    </head>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <br>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="0">
      <tr>
        <td class="page-title"><img src="<%= request.getContextPath()%>/administrator/imgs/page_title.gif" alt="title" width="17" height="12" align="absmiddle">&nbsp;家庭管理 ??   添加家庭成员</td>
      </tr>
    </table>
    <br>
    <div  align="center">
        <div  id="tools" style="width:98%;" >
            <ul>
                <li><a href="#tools-1"><span>添加家庭成员</span></a></li>
            </ul>
            <div id="tools-1" style="border-left:1px #999999 solid;border-bottom:1px #999999 solid;border-right:1px #999999 solid;">
            
           <form name=modifyform action="../../member.html?method=addMember" method="post" onSubmit="return checkData();">
    <table width="98%" height="160" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr> 
          <td width="3%" height="29">&nbsp;</td>
          <td width="35%" align="left" valign="middle">
        <p>成员姓名:<input name="name" type="text" id="name"><span id="name_info" style="letter-spacing: 2px;"></span></p>
                        <p>成员性别:<select name="sex">
                         <option selected="true">男</option>
                            <option>女</option>
                        </select>
                        </p>
                        <p>
                         成员年龄:<input name="age" type="text" id="age">
                        </p>
          </td>
      <td width="47%" align="left" valign="middle">
                      
                        <p>成员密码:<input name="password" type="password" id="password"></p>
                         <p>管&nbsp;理&nbsp;员:<select name="isAdmin">
                         <option>是</option>
                            <option selected="true">否</option>
                        </select>
                        </p>
                        <p>
                         <input name="submit" type="submit" value="添加成员">
                        </p>   </td>
      </tr>
    </table>
    </form>
            </div>
            <div id="tools-2"  style="border-left:1px #999999 solid;border-bottom:1px #999999 solid;border-right:1px #999999 solid;">
            </div>
        </div>
    </div><br>
    <script>
    $("#tools > ul").tabs();
    </script>
    </body>
    </html>