Skip to main content

login application help

1 reply [Last post]
denisopeoluwa
Offline
Joined: 2012-09-17

hello guys, please i need your assistance to resolve an issue i have concerning a login application i built, am still a rookie in java development. i have the following already coded:

login.jsf
login_failure.jsf
login_success.jsf
login_bean.java

my login_bean.java is as follows:

import java.sql.*;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name="login_bean")
@RequestScoped

public class login_bean {
private String username;
private String password;
private String dbusername;

public String getDbpassword(){
return dbpassword;
}

public String getDbusername(){
return dbusername;
}

private String dbpassword;
Connection con;
Statement ps;
ResultSet rs;
String SQL_Str;

public void dbData(String username){
try
{
Class.forName("org.postgresql.Driver");
con =
DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/radar","radar", "radar");
ps= con.createStatement();
SQL_Str="Select * from jsf_users where uname like ('"+username+"')";
rs=ps.executeQuery(SQL_Str);
rs.next();
dbusername=rs.getString(2).toString();
dbpassword=rs.getString(3).toString();

}
catch(Exception ex)
{
System.out.println("Exception Occur :" + ex);
}
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}

public void setUsername(String username) {

this.username = username;
}
public String checkValidUser()
{
dbData(username);
if(username.equalsIgnoreCase(dbusername))

{
if(password.equals(dbpassword)) {
return "valid";
}
else

{

return "invalid";

}

}
else

{

return "invalid";
}
}
}

also i have faces_config.xml as follows:


Loging Page
/login.xhtml

#{login_bean.checkValidUser}
valid
/success.xhtml


#{login_bean.checkValidUser}
invalid
/login_fail.xhtml


ReLoging Page
/login_fail.xhtml

#{login_bean.checkValidUser}
valid
/success.xhtml


#{login_bean.checkValidUser}
invalid
/login_fail.xhtml



/Bundle
bundle


and my web.xml as follows:

javax.faces.PROJECT_STAGE Development

Faces Servlet
javax.faces.webapp.FacesServlet
1


Faces Servlet
/faces/*



30



faces/login.xhtml


FORM
file /login.xhtml /login_fail.xhtml

The challenge am having is that when i try to login with a user stored in the db, the login page is only being presented again. Please kindly help on how i can go about this . thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shingnpr
Offline
Joined: 2012-09-21

In JSF page if there is any problem in success flow then control is redirected to same page.
same is in your case.I can't find problem because their may problem related to logic/db/configuration better you debug the code and check to which extend you moving and have an idea about where it is failing.