2011-10-22 15 views
-1

私はJSFを初めて使用し、JSFでログインスクリプトを作成しようとしています。それはloginsuccessとloginfailureに正常にリダイレクトされます。ユーザーがパスワードを3回間違って入力したときにユーザーをリダイレクトすると、リダイレクトされません - >このエラーが表示されます - > from-view-id '/ indexで一致するナビゲーションケースを見つけることができません。 xhtml 'アクションのために#{login.checkLogin}'と 'loginlocked'という結果を返します。私はNetbeans 7.0を使用しており、faces-config.xmlを見つけることができません。JSFの単純なログイン画面 - 3回の試行のロックアウト

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"; 
     } 

    } 
} 

}

答えて

1

新しいJSF 2.0の暗黙的なナビゲーション機能に依存していると仮定すると、このエラーが基本的にあることを意味しますloginlocked.xhtmlファイルがありません。

faces-config.xmlは、通常、webappの/WEB-INFフォルダにあります。しかし、JSF 2.0では必ずしも必要ではありません。具体的な質問への


無関係は、あなたの豆の主要な設計上の問題があります:

private static int numOfAttempts = 0; 

staticフィールドはクラス、アプリケーションにわたるのすべてインスタンス間で共有されます。 訪問者がパスワードを3回ミスタイプすると、お一人おきにがロックされます。しかし、あなたのコードで別のバグを修正すると起こります。 numOfAttemptsを超過したかどうかを確認する方法がcheckLogin()でない場合は、の前にユーザー名/パスワードを確認してください。したがって、正しいユーザー名/パスワードが入力されると、ロックアウトされたユーザーはまだ正常にログインできます。

あなたの論理的思考と数学のスキルに取り組んでください:)

関連する問題