代码如下.JS不验证直接提交,   谢各位大大 <%@   page   language= "java "   import= "java.util.* "   pageEncoding= "UTF-8 "%> 
<% 
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   'a.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   check(){ 
var   users=document.form.user.value; 
if(users==null){ 
document.write( "请填写 "); 
return   false; 


</script> 
    </head> 
    
    <body> 
        <form   method= "post "   name= "form "   action= "a.jsp "   onSubmit= "return   check() "   > <p> 
        <input   type= "text "   name= "user ">   <input   type= "submit "   name= "connect "> </p> <p> &nbsp; </p> <p> &nbsp; </p> <p> &nbsp; </p> <p> &nbsp; </p> <p> &nbsp; </p> 
</form> 
    </body> 
</html> 

解决方案 »

  1.   

    好乱啊,不高兴拿到eclipse里面试了,你把onSubmit后面的return去掉试试。
      

  2.   

    function check(){
    var users=document.form.user.value;
    if(users==""){
    alert("请填写");
    return false;
    }
    }
    试试,users==null是不正确的哦.
      

  3.   

    补充下:users==null是指这个变量为空对象(或不存在),而不是空字符啊.
      

  4.   

    后面还得加上else return true;
      

  5.   

    <%@       page       language=   "java   "       import=   "java.util.*   "       pageEncoding=   "UTF-8   "%>
    <%   
    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       'a.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 check(){   
    var users=document.getElememtById("user").value;   
    if(users==""){   
    document.write(   "请填写   ");   
    return false;   
    }   
    }   
    </script>
    </head>
    <body>
    <form method="post"name="form"action="a.jsp"onSubmit="return check()">
      <p>
        <input       type=   "text"    id = "user"   name=   "user">
        <input       type=   "submit"   value="提交"    >

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

  6.   

    不验证就对了,因为js里根本就没得到你的form的名字和input text的名字。
    <html>   
       <head>   
                    
       <title>js</title>   
                    <script>   
    function       check(){   
    var       users=document.form.user.value;  
    if(users.length==0){   
    document.write("请填写");   
    return  false;   
    }   
    }   
    </script>   
            </head>   
            
            <body>   
                 <form  method="post" name= "form" action="1.html" onSubmit="return check()" >   <p>   
                    <input       type=   "text"       name=   "user">       <input       type=   "submit"       name="connect">   </p>   <p>   &nbsp;   </p>   <p>   &nbsp;   </p>   <p>   &nbsp;   </p>   <p>   &nbsp;   </p>   <p>   &nbsp;   </p>   
    </form>   
            </body>   
    </html>