mercredi 1 juillet 2015

Unwanted redirect to http://localhost:8080/login/j_security_check after logging in

when I log in, I am redirect to http://localhost:8080/login/j_security_check instead of the desired welcome page wich is specified in the web.xml. This only happens if I log out before, if I log in from scratch it works like a charm.

Login:

xmlns:h="http://ift.tt/J1LPWj"

  xmlns:p="http://ift.tt/HjFrZc">
<h:head>
    <h:outputStylesheet library="css" name="main.css"  />
    <title>Login</title>
</h:head>
<body>
    <div class="login_form">
        <h:form id="login" prependId="false" class="login_form" onsubmit="document.getElementById('login').action = 'j_security_check';">
            <br/><br/>
            <p:graphicImage value="/resources/img/ggs_logo.png" styleClass="login_logo"/>
            <h1>Icosphere</h1> 
            <h1>Data Platform</h1>
            <p:inputText  id="j_username" size="20" />
            <br/>
            <p:password  id="j_password" size="20"/>
            <br/><br/>            
            <p:commandButton id="submit" value="Log in" ajax="false"/>

        </h:form>
    </div>
</body>

Logout:

<html xmlns="http://ift.tt/lH0Osb"
      xmlns:p="http://ift.tt/HjFrZc"
      xmlns:h="http://ift.tt/J1LPWj">
    <body>
        <div class="leftright">
            <span class="aligned">
                <h:form>
                    <p:commandButton ajax="false" action="#{logoutBean.logout()}"
                                     value="Logout!"/>  
                </h:form>          
            </span>
        </div>
    </body>
</html>

Logout Bean:

@Named(value = "logoutBean")
@ApplicationScoped

public class LogoutBean {
public String logout() throws ServletException {
    Principal userPrincipal = 

FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
        return "/login/login.xhtml?faces-redirect=true'";
    }
}

Aucun commentaire:

Enregistrer un commentaire