Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old April 9th, 2002, 11:19 AM
eithne eithne is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 2 eithne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Login Screen Problem

I'm using JSP for my dynamic web page and i am working on the login screen so that when an invalid user logs in the go directly to the error page but when a registered user logs in they go to the first page which is called irishshareprices.jsp. The problem is that no matter if it's a registered user or not it's automatically going to the indexerror.jsp page.

The following is the code i'm using:

<%-- Import required Java Classes --%>
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.sql.*" %>

<%
String user = request.getParameter("username");
String pass = request.getParameter("password");

Connection con=null;
Statement stmt=null;
ResultSet rs=null;

/*if ((user == null)||(pass == null))
{
response.sendRedirect("indexerror.jsp");
}*/


String queryText="SELECT * FROM User WHERE UserID = '" + user + "' AND Password = '" + pass +"'";

try {
//initialize the JDBC-ODBC bridge driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//open a connection to the database
String username = "";
String password = "";
con = DriverManager.getConnection("jdbcdbc:db",username,password);

//execute the query
stmt = con.createStatement();
rs = stmt.executeQuery(queryText);
} catch (Exception e) { }


if ((user == rs.getString("UserID")) && (pass == rs.getString("Password")))
{
response.sendRedirect("irishshareprices.jsp");
}
else
{
response.sendRedirect("indexerror.jsp");
}

%>

Reply With Quote
  #2  
Old April 10th, 2002, 07:35 AM
oscagne oscagne is offline
Java Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 5 oscagne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You are comparing strings, so == won't work unless these to string object references are the same. You need to use something like

if ((user.equals(rs.getString("UserID"))) && (pass.equals(rs.getString("Password"))))

Reply With Quote
  #3  
Old April 10th, 2002, 07:42 AM
eithne eithne is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 2 eithne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi, thanks for your reply

I tried what you suggested but I got an internal server error. I put in the following line:
if ((user.equals("UserID")) && (pass.equals("Password")))

but it's still going to the indexerror page instead of the proper one. Is there anyway I can check if there is anything in rs so I can check if the database is picking anything up cause I can't understand why the code is automatically going to the error page.

Reply With Quote
  #4  
Old April 10th, 2002, 10:57 AM
oscagne oscagne is offline
Java Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 5 oscagne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'd recommend then taking out the redirect code and putting in a variable printed to the screen. I don't do JSP, but I'm guessing it'll be something like

user id = "<%=rs.getString("UserID")%>"
typed user id = "<%=user%>"
Password = "<%=rs.getString("Password")%>"
typed Password = "<%=Password%>"

You should be able to tell the differences from this

Reply With Quote
  #5  
Old April 10th, 2002, 11:10 AM
oscagne oscagne is offline
Java Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 5 oscagne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
And it's probably not gonna print out anything meaningful, as you need to call the .next() method on the resultset before printing the results cos until you call that it sits point before the first row in the result set (not at it)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Login Screen Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway