我新的JSF,並試圖創建JSF登錄腳本。它成功地重定向到loginsuccess和loginfailure。但是,當談到重定向用戶當用戶輸入的密碼不正確的3倍,它不重定向 - >它給了我這個錯誤 - >無法找到與-view-id的「/折射率匹配導航的情況下。 xhtml'進行操作'#{login.checkLogin}',並得到'loginlocked'結果。我正在使用Netbeans 7.0,無法找到faces-config.xml。JSF簡單的登錄屏幕 - 三個錯誤嘗試鎖定
的Index.html
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<head><title>JSF Login</title></head>
<body>
<h:form>
<table>
<tr>
<td><h:outputText value="Username: " /></td>
<td><h:inputText id="loginname"
value="#{login.userName}" />
</td>
</tr>
<tr>
<td><h:outputText value="Password: " /></td>
<td><h:inputSecret id="password"
value="#{login.password}" />
</td>
</tr>
<tr>
<td> </td>
<td><h:commandButton value="Login"
action="#{login.checkLogin}"/>
</td>
</tr>
</table>
<h:outputLabel value="#{login.label1}" />
</h:form>
</body>
</html>
loginBean.java
package login;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="login")
@RequestScoped
public class loginBean {
private String userName;
private String password;
private String label1;
private static int numOfAttempts = 0;
/** Creates a new instance of loginBean */
public loginBean() {
}
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the label1
*/
public String getLabel1() {
return label1;
}
/**
* @param label1 the label1 to set
*/
public void setLabel1(String label1) {
this.label1 = label1;
}
public String checkLogin()
{
if (userName.equals("Neetu") && password.equals("123456"))
{
this.setLabel1("Login Success");
return "loginsuccess";
}
else
{
numOfAttempts++;
if (numOfAttempts >= 3)
{
this.setLabel1("Account Locked");
return "loginlocked";
}
else
{
this.setLabel1("Login Failure" + numOfAttempts);
return "loginfailure";
}
}
}
}