|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
I 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 dbc: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"/> } 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! ------------------------------------------------------------------------------------ |
|
#2
|
|||
|
|||
|
Re: I'll take a large coke and a mentor please..
There is nothing wrong with the code...except for the user authentication...u can let the database do that work for u...u r using an while loop...instead u can try using a query like
select email from people where Email = request.getParameter("userID"); if rs.next() login successfull else login failed |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > I'll take a large coke and a mentor please.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|