我目前正在尝试为我的项目执行登录和注销JSF身份验证方法。
我正在经历几个类并与数据库建立联系以便从数据库中获取价值。
当我完成对类查询的所有必要属性的编译后,我运行并显示以下错误:Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
[我假设在创建一个类以加载JDBC
驱动程序以传递URL时可能出错。这是连接类:
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";
}
[请帮助我找到我没有发现的错误。如果问题不在上述类别中,可能是哪里出了问题?
浏览器(firefox)由于infinite重定向而无法加载网站。您不知何故一遍又一遍地重定向到同一页面,因此firefox终止了请求以节省性能。
因此,由于您没有更精确地编辑问题,所以我只能像您一样提供示例问题。
想象您在站点test
上,并且在此站点上执行一些操作,并根据某些结果,要转到页面test
(刷新)或abc
。无论如何,结果始终是相同的,因此您可以永久重定向,并且Firefox会停止它,以免浪费性能。
类似于上一个示例:假设您必须访问站点,并且一个站点重定向到另一个站点,所以您从test
转到abc
,然后永远返回。 (我认为Firefox无法识别并阻止这种情况)
此问题的解决方案非常简单:只需在重定向之前添加if
语句,即可仅在不在该站点上时进行重定向。
传递操作不应该重定向的信息。
示例1:
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); if (!"yourSite".equals(request.getRequestURI()) { return "/yourSite.xhtml"; } else { return null; }
示例2: