Help! JSP Login
I have create a jsp called admin_validate.jsp, when i key in the admin id and admin password, the admin_validate will check the database and print a proporiate messages. the problem is it will check one by one and wont stop until the end of record and print out message one by one. How to solve the problem? thank you very much
[u]this is the admin_validate.jsp code:</u>
<%@ page import="java.sql.*" %>
<%
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/sers";
String username = "root";
String SQLPassword = "123";
Connection con = null;
Statement statement = null;
ResultSet rs = null;
%>
<html>
<head>
<title>Administrator Authentication</title>
</head>
<body>
<%
Class.forName(driver);
con = DriverManager.getConnection(url,username,SQLPasswo rd);
statement = con.createStatement();
rs = statement.executeQuery("SELECT admin_id,admin_password FROM admin");
while(rs.next())
{
String DbAdminId = rs.getString("admin_id");
String DbAdminPw = rs.getString("admin_password");
String idValidate = request.getParameter("userid");
String pwValidate = request.getParameter("password");
if(idValidate.equals(DbAdminId) && pwValidate.equals(DbAdminPw))
{
out.println("<h1 align=center>" + "Login Successful!" + "</h1>");
}
else
{
out.println("<h1 align=center>" + "Login Fail!" + "</h1>");
}
}
con.close();
%>
</body
</html>
|