基于JSF2表单的身份验证注销

时间:2015-04-29 11:51:40

标签: java jsf-2 basic-authentication logout

我使用的是jsf2,我在退出时遇到了问题。

事实上连接到我的应用程序的网址是

http://localhost:8080/myapplication/

这是配置:

的login.jsp

<form method="post" action="j_security_check">
            <table>
                <tr>
                    <td>NNI :</td>
                    <td><input type="text" name="j_username"/></td>
                </tr>
                <tr>
                    <td>Mot de passe :</td>
                    <td><input type="password" name="j_password"/></td>
                </tr>
                <tr>
                    <td colspan="2" align="right"><input type="submit" value="Identifier"></td>
                </tr>
            </table>
        </form>

的web.xml

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.jsp</form-login-page>
        <form-error-page>/login_failed.jsp</form-error-page>
    </form-login-config>
</login-config>

所有工作都可以正常进行身份验证,我会重定向到index.jsp

的index.jsp

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head></head>
    <body>
        <jsp:forward page="/pages/start.jsf" />     
    </body>
</html>

和start.xhtml是我的主页。

然后我添加了一个LoginBean:

public String logout() throws IOException {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    externalContext.invalidateSession();

    return "logout";
}

并在 faces-config.xml

<navigation-rule>
    <from-view-id>/*</from-view-id>
    <navigation-case>
        <from-outcome>logout</from-outcome>
        <to-view-id>/login.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
</navigation-rule>

当我点击退出时,我会重定向到:

http://localhost:8080/myapplication/login.jsp

但是当我尝试重新登录时,登录页面显示另一次,所以我尝试再次登录,但我有错误消息:

Etat HTTP 404 - /castorsurveillance-web/j_security_check

当我注销重定向到

时,它是否可行
http://localhost:8080/myapplication/

而不是

http://localhost:8080/myapplication/login.jsp 

或其他解决方案,如果存在最好的解决方案! :)

谢谢!

0 个答案:

没有答案
相关问题