0

我有commandButton,它将我从“login.xhtml”重定向到“home.xhtm”。登录成功,但重定向不起作用;没有任何错误。

面孔-config.xhtml

<navigation-rule>
        <from-view-id>/public/login.xhtml</from-view-id>
        <navigation-case>
        <from-action>#{userLoginBean.login}</from-action>
            <from-outcome>login</from-outcome>
            <to-view-id>/public/home.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

托管豆:

@RequestScoped
public class UserLoginBean{
..
...
..
 
public String login() throws ServletException, IOException{
    try
    {
      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); 
      HttpServletRequest request = ((HttpServletRequest)context.getRequest());
            
      ServletResponse resposnse = ((ServletResponse)context.getResponse());
      RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");
      dispatcher.forward(request, resposnse);
      FacesContext.getCurrentInstance().responseComplete();
      
      System.out.println("logiiiin");
      return "login";
    }
    catch (Exception ex) {
        ex.printStackTrace();
        System.out.println(ex.getMessage());
        System.out.println("Login Failed");
        FacesContext.getCurrentInstance()
                .addMessage(
                        "formLogin",
                        new FacesMessage(FacesMessage.SEVERITY_WARN,
                                "Login or Password Failed",
                                "User Name and Password Not Match!"));
         return"null";
    }

和 .xhtml :

<f:facet name="footer">
                <center>
                    <p:commandButton  value="Se connecter" action="#{userLoginBean.login}" />
                </center>
            </f:facet>
4

1 回答 1

0

尝试在没有任何业务逻辑的情况下重定向到您的页面,即返回“登录”;并验证下一页位置

于 2013-05-18T09:29:41.567 回答