rs.next() not working! Why not???
843835Mar 20 2002 — edited Mar 22 2002I am a newbie at JSP, but think I have got a pretty good hold on it. I have a C++ background, and have started Java over the past 6 months. I have taken on a little project of sorts and would like some help if possible, just advice on my code and such. What I want to do is, have a user login with his email, the email will be validated against the Email field in the People table, and if it exists a session variable loggedin will be set to true, and passed onto the form page for a survey to be filled out. I would like someone to check the logic and syntax of my code here, to let me know I am good to go, or totally off. haha.
Here is the flow:
1. login.html
2. processlogin.jsp (if invalid login -> errorpage.jsp)
3. form.jsp
Code is below:
------------------------------------------------------------------------------------
login.html
------------------------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form method="POST" action="processLogin.jsp" name="logon">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="200">
<tr>
<td width="50%">Name</td>
<td width="50"><input type="text" name="userID"></td>
</tr>
<tr>
<td width="50%">Password</td>
<td width="50%"><input type="password" name="pwd"></td>
</tr>
<tr>
<td width="50%" colspan="2" align="center">
<input type="submit" value="submit">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
------------------------------------------------------------------------------------
processlogin.jsp
------------------------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ page import = "java.sql.*" %>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<%
Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:database-Name-Here", "loginId", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT Email FROM People");
String user_id = request.getParameter("userID");
while(rs.next())
{
if ( user_id.equalsIgnoreCase(rs.getString("Email")) );
{
<jsp:forward page="form.html"/>
session.setAttribute("LoggedIn", "true");
}
else
<jsp:forward page="loginfailed.html"/>
}
rs.close();
con.close();
%>
</body>
</html>
------------------------------------------------------------------------------------
errorpage.jsp
------------------------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div align="center">
<p> </p>
<p> </p>
<p> <font color="#FF0000">* Login Failed *</font></p>
<hr>
<p> </p>
</div>
<%@ include file="login.html" %>
</body>
</html>
------------------------------------------------------------------------------------
form.jsp
------------------------------------------------------------------------------------
<html>
<head>
<title>Survey Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<%
String valid = (String) session.getAttribute("LoggedIn");
if ( valid.equals("true"))
{
<!-- The form and all the other stuff goes here. -->
}
else
<jsp:forward page="errorpage.jsp" />
%>
</body>
</html>
------------------------------------------------------------------------------------
the end!
------------------------------------------------------------------------------------