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

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;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程