Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 1st, 2005, 03:10 AM
Authorized User
 
Join Date: Nov 2005
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>

  #2 (permalink)  
Old December 8th, 2005, 02:35 AM
Registered User
 
Join Date: Nov 2005
Location: Bombay, Maharashtra, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to bytepower
Default

Use this instead of your code -

<%

String sql = "select * from admin where username='"+postusername+"' and password='"+postpassward+"'";

Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(sql);

%>

Arvind Jagtap,
Software Engineer,Bombay


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP and LOGIN cbolat JSP Basics 3 November 30th, 2005 04:11 AM
jsp login page ronnie JSP Basics 4 April 12th, 2005 11:45 PM
jsp & mysql login code sos jaymak121 Java Databases 4 November 25th, 2004 06:50 AM
Help with jsp login page javaStudent JSP Basics 0 January 27th, 2004 06:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.