Hi all,
I am new here, and new to java in general. I am taking my Java III class in college and have a project to make a web project with a login servlet for a bank. The login servlet takes the id and password you enter, checks the database, and returns HTML code Invalid or valid based on whether the ID and password match or not. That much I have working. However, if I enter a username and password that is not in the databse, I get a blank page instead of invalid login. I can not figure this out for the life of me. I meant to ask my teacher today, But with hurricane Irma being around class was cancelled. I am using ucanaccess for the databse driver in netbeans.
protected void processRequest(HttpServletRequest request, HttpServletResponse response){ response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String id; String pw; String iddb=""; String pwdb=""; id = request.getParameter("idtd"); pw = request.getParameter("pwtd"); System.out.println(id); System.out.println(pw); //Load Driver Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); String connURL="jdbc:ucanaccess://c:\\Users\\Bryan\\Desktop\\ChattBankMDB.mdb"; //Get Connection Connection con = DriverManager.getConnection(connURL); //Create Statement Statement stmt = con.createStatement(); //Execute Statement String sql; ResultSet rs; sql = "Select * from Customers where CustID = '"+id+"'"; System.out.println(sql); rs = stmt.executeQuery(sql); rs.next(); iddb = rs.getString("CustId"); pwdb = rs.getString("CustPassword"); System.out.println(iddb); System.out.println(pwdb); if (id.equals(iddb) && pw.equals(pwdb)){ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>ChattBank</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Valid Login<h1>"); out.println("</body>"); out.println("</html>"); }//end if else{ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>ChattBank</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Invalid Login<h1>"); out.println("</body>"); out.println("</html>"); }//end else }//end try catch(Exception e){ System.out.println(e); }//end catch }//end process request[COLOR="Silver"] [/COLOR]
--- Update ---
Sorry. Everything is indented when I submit or try to edit. I am not sure why it isn't in the post.