Wrox Programmer Forums
|
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
 
Old April 25th, 2006, 08:47 AM
Authorized User
 
Join Date: Aug 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Calverstine Send a message via MSN to Calverstine
Default login issue

<%@ page import="java.sql.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.io.*" %>
<%
    String username=request.getParameter("username");
    String password=request.getParameter("password");
    out.println(password);
    String connectionURL = "jdbc:mysql://localhost:3306/jsplogin?user=root;password=";
    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
    connection = DriverManager.getConnection(connectionURL, "", "");
    statement = connection.createStatement();
    rs = statement.executeQuery("SELECT * FROM jsplogin WHERE username='"+username+"'");
    rs.first();
    String temp=rs.getString("password");
    out.println(temp==password);
    if (temp==password) {
        response.sendRedirect("correct.htm");
    }else
    {
    }
    rs.close();


%>

To simulate a simple login, i need to open a database connection, then connect to database, and compare wheather the user name and password match. Now the problem is, the executed statement whenever compared to the password post from a form, it returns a false value, which will never be authenticated, why, any solution??

 
Old July 3rd, 2006, 05:28 AM
Authorized User
 
Join Date: Jun 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Replace "==" comparision with equals() method. Since when "==" operator is used for comparing two objects. It will compare the references of those objects and not actual content in those objects(since Strings are also objects). To compare the actual value in those String objects we need to use equals() method (of Object class) which is overridden in String class to meet this purpose.

prasanth.c
 
Old January 12th, 2007, 03:25 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what if there's 5 users and they have different positions.

what's the code for login if every user has corresponding page to go to..?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Login issue [RESOLVED] yugolancer BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 19 March 7th, 2008 04:14 PM
login issue. using asp and access teknet Access ASP 9 February 9th, 2005 01:49 AM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM





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