vendredi 24 juillet 2015

error in login form which is fetching data from database but it is not comparing using if statement

i found some problems in login form which is fetching data from database but it is not comparing

login.jsp

<form action="check.jsp" method="post" name="myForm" >
<table align="center" bgcolor="#66ccff" cellpadding="10dx" cellspacing="20dx">

    <tr>
        <td><b>Username </b></td>
        <td><b>:</b></td>
        <td><input type="text" name="un1" placeholder="Enter User Name..."></td>
    </tr>

    <tr>
        <td><b>Password </b></td>
        <td><b>:</b></td>
        <td><input type="password" name="ps1" placeholder="Enter Your Password..."></td>
    </tr>
</table>    
    </br>

<table align="center" bgcolor="#99ff33">    
    <tr>
        <td><input type="submit" name="submit" align="center" style="color: green" value="Login"></td>
    </tr>

</table>
<% String e1 =(String)session.getAttribute("k");
if(e1!=null){%>
<table align="center">
  <tr>
    <td style="color: red;"><%out.println("Username or Password is Wrong.");
    session.removeAttribute("k"); %></td>
  </tr>
</table> <%
}

%>

check.jsp encounterd an error. request.getAttributes and stored in strings and compared it though its nor working whats the matter?

<%@ page import="java.sql.*" %>
<%  
    String url="jdbc:mysql://localhost:3306/home";
    String user="root";
    String password="root";

    Class.forName("com.mysql.jdbc.Driver");

    //get connection
     Connection con = DriverManager.getConnection(url,user,password);

    //creat statement
    Statement st=con.createStatement();

    ResultSet rs=st.executeQuery("select uname,pswrd from regestration");

    while(rs.next()) {
        String s1 = request.getParameter("Un1");
        String s2 = request.getParameter("ps1");
        String s5="hello";
        String s3=rs.getString("uname");
        String s4=rs.getString("pswrd");

        if (s1.equals(s3) && s2.equals(s4)) 
        {
            response.sendRedirect("welcome.jsp");
        }
        else {
        session.setAttribute("k", s5);
        response.sendRedirect("login.jsp");
    }
%>
    }   
%>

Aucun commentaire:

Enregistrer un commentaire