Posted By:
Gaurav_Bhargava
Posted On:
Monday, March 26, 2001 09:14 PM
Hi There I have written a simple bean which contacts with the database and checks for the Login Name and password, i am calling it through a jsp the code for which is scope = "application"/> scope = "session" /> <%! String nextPage; %> <% if(loginManager.login(credentials)) { nextPage = "MainMenu.jsp"; } else if(loginManager.alreadyLoggedIn(credentials)) { nextPage = "Duplicatelogin.jsp"; } else { nextPage = "LoginFailure.jsp"; } %> <%= nextPage %>"/> and the bean is package com.instantjsp; imp
More>>
Hi There
I have written a simple bean which contacts with the database and checks for the Login Name and password, i am calling it through a jsp the code for which is
scope = "application"/>
scope = "session" />
<%! String nextPage; %>
<% if(loginManager.login(credentials)) {
nextPage = "MainMenu.jsp";
}
else if(loginManager.alreadyLoggedIn(credentials)) {
nextPage = "Duplicatelogin.jsp";
}
else {
nextPage = "LoginFailure.jsp";
}
%>
<%= nextPage %>"/>
and the bean is
package com.instantjsp;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.Hashtable;
import javaservlets.jdbc.*;
public class LoginManager implements java.io.serializable {
private Hashtable currentLogins;
private ConnectionPool connectionpool;
private static final String SELECT_PASSWORD =
"SELECT Password from LoginInfo WHERE UserID = ";
private static final String QUOTE = "'";
private class LoginProfile extends UserCredentials {
boolean isLoggedIn = false;
public LoginProfile(UserCredentials credentials) {
setUser(credentials.getUser());
setpassword(credentials.getPassword());
setSessionId(credentials.getsessionId());
isLoggedIn = false;
}
}
public LoginManager() throws Exception {
connectionpool = new ConnectionPool();
connectionpool.initialize();
currentLogins = new Hashtable();
}
public boolean alreadyLoggedIn(UserCredentials credentials) {
boolean loggedIn = false;
String user = credentials.getUser();
if(currentLogins.containsKey(user)) {
LoginProfile aProfile = (LoginProfile)currentLogins.get(user);
loggedIn = aProfile.isLoggedIn;
}
return loggedIn;
}
public boolean login(UserCredentials credentials) throws SQLException {
if(alreadyLoggedIn(credentials)) {
return false;
}
LoginProfile profile = new LoginProfile(credentials);
Connection conn = connectionpool.getConnection();
Statement qs = conn.createStatement();
ResultSet rs = qs.executeQuery(SELECT_PASSWORD + QUOTE + credentials.getUser() + QUOTE);
while (rs.next()) {
if(rs.getString(1).equals(credentials.getPassword())) {
profile.isLoggedIn = true;
currentLogins.put(credentials.getUser(),profile);
break;
}
}
return profile.isLoggedIn;
}
}
now when i am trying to see the jsp page it gives the following error
javax.servlet.ServletException: Cannot create bean of class com.instantjsp.LoginManager
Error: 500
Location: /ValidateUser.jsp
Internal Servlet Error:
i Have another class called UserCredentials.java which just gets and sets the userid and password
i know its a big query...i am sorry, but its eating my head..
Thanks a lot..
Regards
Gaurav