半夏莲城
2019-04-05 14:20
采纳率: 100%
浏览 2.1k
已采纳

jsp页面中script的代码为什么会不起作用?

<script language="javascript">
      function isNull(str)
      {
         if (str.length==0)
           return true;
         else
           return false;
      }
      function isValidate(form)
      {
         userid1=form.userid1.value;
         userpass=form.userpass.value;
         if(isNull(userid1))
         {
           alert("请输入账号!");
           return false;
         }
         if(isNull(userpass))
         {
           alert("请输入密码!");
           return false;
         }
         return true;
      }
    </script>

这部分的代码在登录的时候不起作用,账号密码没填就点击登录,alert内的内容没有弹出来,反而是直接运行了相关的servlet文件,就像请问这要怎么解决?完整的jsp代码在下面

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
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 'loginUser1.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 isNull(str)
      {
         if (str.length==0)
           return true;
         else
           return false;
      }
      function isValidate(form)
      {
         userid1=form.userid1.value;
         userpass=form.userpass.value;
         if(isNull(userid1))
         {
           alert("请输入账号!");
           return false;
         }
         if(isNull(userpass))
         {
           alert("请输入密码!");
           return false;
         }
         return true;
      }
    </script>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


  </head>

  <body>
    <form id="loginUser1" name="loginUser1" method="post" action="UserLoginServlet1" onSubmit="return isValidate(loginUser1)"><br><br>
    <p align="center">账&nbsp;&nbsp;&nbsp;&nbsp;号:
      <input type="text" name="userid1" class="ipt-t"  />
    </p>
    <p align="center">密&nbsp;&nbsp;&nbsp;&nbsp;码:
      <input type="password" name="userpass1" class="ipt-t" />
    </p>
    <p align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" name="submit" value="登录" />&nbsp;&nbsp;&nbsp;
      <input type="reset" value="清空" name="reset" />
    </form>
  </body>
</html>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 天际的海浪 2019-04-05 14:32
    已采纳

    userpass=form.userpass1.value;

    点赞 评论

相关推荐 更多相似问题