-1

How can I display the error message as part of validation controls in jsp code given below? Where should I include the code? I have tried using out.print("Invalid username or password"); in between these codes, but it doesnt work!

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>
Navi
  • 1
  • 3

1 Answers1

0

An 'alert' statement next to 'if' statement as an else is actually working but not when the username or password is wrong. Pls do help.

Navi
  • 1
  • 3