Jsf 不需要的重定向到http://localhost:8080/login/j_security_check 登录后

Jsf 不需要的重定向到http://localhost:8080/login/j_security_check 登录后,jsf,jakarta-ee,login,j-security-check,Jsf,Jakarta Ee,Login,J Security Check,当我登录时,我被重定向到web.xml中指定的欢迎页面,而不是所需的欢迎页面。这只发生在我以前注销时,如果我从头开始登录,它就像一个符咒 登录页面 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:p="http://primefaces.org/ui"> <h:head> <h

当我登录时,我被重定向到web.xml中指定的欢迎页面,而不是所需的欢迎页面。这只发生在我以前注销时,如果我从头开始登录,它就像一个符咒

登录页面

<html xmlns="http://www.w3.org/1999/xhtml"      
      xmlns:h="http://xmlns.jcp.org/jsf/html"

      xmlns:p="http://primefaces.org/ui">
    <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>
</html>

您的LogoutBean需要重定向到“欢迎”页面,而不是登录表单

每当客户端请求受保护的资源时,标准web安全性都会显示指定的登录表单。当用户通过身份验证后,容器返回最初请求的资源

因此,发生的事情是您故意试图显示登录表单;但是它是受保护的,所以容器会将您重定向到相同的登录表单;用户进行身份验证,然后返回最初请求的登录表单


因此,您永远不会直接链接到登录页面。一旦请求受保护的资源,它将始终显示。

您的登录表单也受声明保护吗?
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <body>
        <div class="leftright">
            <span class="aligned">
                <h:form>
                    <p:commandButton ajax="false" action="#{logoutBean.logout()}"
                                     value="Logout!"/>  
                </h:form>          
            </span>
        </div>
    </body>
</html>
@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'";
    }
}