I am currently trying to do login & logout JSF authentication method for my project.
I am going through several classes and connection with database in order to get value from database.
When i'm finished compiling all necessary attributes on my classes query, i run and it shows me error as follows: Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
I assume that I may have mistake while i created a class to load my JDBC
driver to pass the URL. Here is the connection class:
public class DataConnect {
public static Connection getConnection() {
try {
Class.forName("org.hibernate.dialect.MySQLDialect");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/epda_assignment?zeroDateTimeBehavior=convertToNull", "root", "kok123");
return con;
} catch (ClassNotFoundException | SQLException ex) {
System.out.println("Database.getConnection() Error -->"
+ ex.getMessage());
return null;
}
}
public static void close(Connection con) {
try {
con.close();
} catch (SQLException ex) {
}
}
LoginBean.java
public class LoginBean implements Serializable{
private String email2;
private String msg;
private String password2;
public String processRequest() {
boolean valid = UserDao.validate(email2, password2);
if (valid) {
HttpSession session = SessionUtil.getSession();
session.setAttribute("email2", email2);
session.setAttribute("password2", password2);
return "after_login";
} else {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"Incorrect Username and Passowrd",
"Please enter correct username and Password"));
return "home";
}
}
//logout event, invalidate session
public String logout() {
HttpSession session = SessionUtil.getSession();
session.invalidate();
return "home";
}
home.xhtml
<table>
<tr>
<td> <h:outputLabel for="email2">Enter your Email: </h:outputLabel></td>
<td><h:inputText id="email2" value="#{loginBean.email2}"/></td>
</tr>
<tr>
<td> <h:outputLabel for="passwrod2">Password: </h:outputLabel></td>
<td><h:inputText id="password2" value="#{loginBean.password2}"/></td>
</tr>
<td><h:commandButton id="submit-button" value="Submit" action="#{loginBean.processRequest}"/></td>
<td></td>
</table>
after_login.xhtml
<h:body>
<h:form>
<p>Welcome #{registerBean.fullName_}</p>
<h:commandLink action="#{loginBean.logout}" value="Logout"></h:commandLink>
</h:form>
</h:body>
Please help me to find the mistake i didn't see. If the problem is not on the above class, where could be the problem?