I have written a
jsp page which compares the username and password entered in a form with the username and password stored in the database. This works fine when the correct information is entered but when the data is incorrect no error message is displayed, the page is simply blank.
Here is the code :
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
if( (username!=null) && (password!=null) )
{
String findUser = "SELECT Username, Password FROM User WHERE username LIKE '"+ username +"' AND password LIKE '"+ password +"'";
String dsn = "mcaiysm3";
String dbURL = "jdbc
dbc:" + dsn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL,"","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(findUser);
while(rs.next()) {
String dbUser = rs.getString("username");
String dbPassword = rs.getString("password");
if( (dbUser.equalsIgnoreCase(request.getParameter("username"))) && (dbPassword.equalsIgnoreCase(request.getParameter("password"))) )
{ %> <input type="hidden" name="username" value="<%=dbUser%>">
<jsp:forward page="Welcome.jsp"/>
<%
}
else if (rs==null) {
out.print("Invalid login details");
%> <jsp:forward page="Login.jsp"/> <%
}
rs.close();
stmt.close();
con.close();
}
}
%>
I have tried using a try-catch, if-else to get an error message but nothing seems to work. Can anyone please help?