【问题标题】:jsp code to display error message in validation. Where should I include in this code?用于在验证中显示错误消息的 jsp 代码。我应该在此代码中包含哪些内容?
【发布时间】:2017-09-16 13:55:29
【问题描述】:

如何在下面给出的 jsp 代码中将错误消息显示为验证控件的一部分?我应该在哪里包含代码?我试过使用 out.print("Invalid username or password");在这些代码之间,但它不起作用!

adminlogin.html

<body>



                 <!-----start-main---->
                <div class="login-form">
                        <h1>Admin Sign In</h1>
                        <h2><a href="#"></a></h2>
                                                <form action="adminlog.jsp" method="post">
                    <li>
                                            <input type="text" class="text" name="uname" value="User Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'User Name';}"><a href="#" class=" icon user"></a>
                    </li>
                    <li>
                                            <input type="password" value="Password" name="pass" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Password';}"><a href="#" class=" icon lock"></a>
                    </li>

                     <div class ="forgot">
                        <h3><a href="changepw.jsp">Forgot Password?</a></h3>
                        <input type="submit" onclick="myFunction()" value="Sign In" ><a href="admin.jsp" class=" icon arrow"></a>                                                                                                                                                                                                                                  </h4>
                    </div>
                </form>

adminlog.jsp

<body>
       <%
    String a=request.getParameter("uname");
    String b=request.getParameter("pass");
    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/eventdb?zeroDateTimeBehavior=convertToNull", "root", "1111");
        Statement st=con.createStatement();
        String str="select * from adminlogin where username='"+a+"' and password='"+b+"'";
        ResultSet rs=st.executeQuery(str);
       if(rs.next())
        {
            response.sendRedirect("admin.jsp");
        }
       else
       {
           response.sendRedirect("adminlogin.html");              

       }
    }
    catch(Exception e)
    {
        out.println(e.getMessage());
    }
    %>
    </body>

【问题讨论】:

    标签: html mysql jsp netbeans-8 glassfish-4


    【解决方案1】:

    'if' 语句旁边的 'alert' 语句作为 else 确实有效,但在用户名或密码错误时无效。请帮忙。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      相关资源
      最近更新 更多