Hi,
I'm currently doing a
JSP Project for school, one of my pages is a form where users can log in, their usernames & passwords are stored in a DB.
Here's the code for my code for the form:
[LogIn.jsp]
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<HTML>
<HEAD><TITLE>Log Gebruiker in</TITLE>
<link rel="stylesheet" href="gip.css" type="text/css">
</HEAD>
<BODY>
<P>
<P>
<P>
<P><img src="images/wsbeheer.gif" width="101" height="11"><br>
<br>
<a href="toevoegen.jsp">Produkten toevoegen</a>
<FORM name="form1" method="post" action="LogInVerwerking.jsp">
<TABLE border=1 cellpadding=0 cellspacing=0>
<TR>
<TD>Gebruikersnaam: </TD>
<TD>
<INPUT type="text" name="GebruikerIn" maxlength="10">
</TD>
</TR>
<BR>
<TR>
<TD>Wachtwoord: </TD>
<TD>
<INPUT type="password" name="WachtwoordIn" maxlength="20">
</TD>
</TR>
<BR>
</TABLE>
<INPUT type="submit" name="Submit" value="Submit">
</FORM>
<P>
</BODY>
</HTML>
The code that handles the form:
[LogInVerwerking.jsp]
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc

dbc:Gebruikers";
con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
String user;
String password;
gebruiker=request.getParameter("GebruikerIn");
wachtwoord=request.getParameter("WachtwoordIn");
ResultSet rs = stmt.executeQuery("SELECT * FROM tblGebruikers WHERE USERNAME='"+user+"' AND PASSWORD='"+password+"'");
while(rs.next()){
String dbUser = rs.getString("USERNAME");
String dbPassword= rs.getString("PASSWORD");
boolean entrance;
entrance=false;
if ((user.equals(dbUser)) && (password.equals(dbPassword))){
entrance=true;
}
else{
entrance=false;
}
if (entrance==true){%>
<jsp:forward page="Entrance.jsp"/>
<%}
else{%>
<jsp:forward page="NoEntrance.jsp"/>
<%}
}
%>
Now, the problem is here;
When I put in the correct login & password it forwards me to the 'entrace.jsp' page, but when it's incorrect, instead of redirecting me to the other page it gives me a blank page.. When i switch the first 'entrance==true' to 'false' it redirects me to the 'NoEntrance.jsp' page.. So it doesn't even check if 'entrance' could be false.. (i think)
Your help is greatly appreciated,
Michael