2010-10-19 25 views
1

Performing user authentication in Java EE/JSF using j_security_check使用JSF 2.0進行activatin FORM驗證的問題

我試過這個解決方案。但是,如果我把這個給我的配置

<login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>sql</realm-name> 
    <form-login-config> 
     <form-login-page>/login.xhtml</form-login-page> 
     <form-error-page>/index.xhtml</form-error-page> 
    </form-login-config> 
</login-config> 

,而不是

<login-config> 
    <auth-method>BASIC</auth-method> 
    <realm-name>sql</realm-name> 
</login-config> 

基本身份驗證的登錄彈出顯示不出來了..這是我aspected。 但是接下來的登錄頁面沒有Inputfields ..沒有一個faclet代碼已經被執行。那怎麼可能?

我login.xhtml代碼:

<!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" 
     xmlns:f="http://java.sun.com/jsf/core"> 

    <h:head> 
     <title>Login</title> 
    </h:head> 
    <h:body> 

     <form action="j_security_check" method="post"> 
      <h:outputLabel for="j_username">Username:</h:outputLabel> 
      <h:inputText id="j_username" required="true" /> 
      <h:message for="j_username" /> 
      <br /> 
      <h:outputLabel for="j_password">Password:</h:outputLabel> 
      <h:inputSecret id="j_password" required="true" /> 
      <h:message for="j_password" /> 
      <br /> 
      <h:commandButton value="Login" /> 
     </form> 
    </h:body> 
</html> 

這就是所有的顯示內容

Username: 
Password: 

回答

1

換句話說,該FacesServlet不會被調用。作爲另一個證據,在瀏覽器中右鍵單擊頁面,選擇查看源文件,您將看到JSF標記未被處理。 FacesServlet是負責這個的人。

您需要更改登錄頁面的URL以匹配FacesServleturl-pattern。如果是這樣,例如*.jsf,然後更新內容如下:

<form-login-page>/login.jsf</form-login-page> 
+0

好吧這是<表單登錄頁> /faces/login.xhtml 謝謝你把我推在正確的方向..我Forgt的Faces Servlet自動地映射所有Faclets!謝謝! – Markus 2010-10-19 13:17:33

+1

不客氣。您也可以將'FacesServlet'映射到'* .xhtml',然後您就不必擔心這一切。 – BalusC 2010-10-19 13:20:30

+0

我認爲這個映射是在一個虛擬目錄? Faces Servlet * .xhtml 會起作用嗎? – Markus 2010-10-19 14:04:18