会话null jsf getExternalContext()

时间:2019-06-20 19:16:52

标签: jsf primefaces

我在代码中生成了一个会话,但是当在另一个文件中使用该会话时,该会话将返回null,即全部!

此linux服务器的主要符号,payara 5

public Usuarios loginUsuario(String usuario, String password) {
    Usuarios user = null;
    try {
        UsuariosDAO us = new UsuariosDAO();
        user = us.loginUsuario(usuario, password);
        if (user != null) {
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("usuario", user); // here set user ok! not null
            FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
        } else {
            FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Atencion!", "User o Password Inconrrectos"));
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    return user;

}
public void probarSession() {
    try {
        FacesContext esta = FacesContext.getCurrentInstance();
         System.err.println(esta.getExternalContext().getSessionMap().get("usuario")+"this is null!!!");
        Usuarios us = (Usuarios) esta.getExternalContext().getSessionMap().get("usuario");

        if (us == null) {
            esta.getExternalContext().redirect("login.xhtml");
        }
    } catch (IOException e) {
        System.err.println(e);
    }

}

0 个答案:

没有答案