Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 20th, 2002, 09:19 AM
tbetten tbetten is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 0 tbetten User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question I'll take a large coke and a mentor please..

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("jdbcdbc: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>&nbsp;</p>
<p>&nbsp;</p>
<p> <font color="#FF0000">* Login Failed *</font></p>
<hr>
<p>&nbsp;</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!
------------------------------------------------------------------------------------

Reply With Quote
  #2  
Old March 26th, 2002, 03:19 AM
aabha aabha is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: India
Posts: 7 aabha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to aabha
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > I'll take a large coke and a mentor please..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway