Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Ao reiniciar o servidor o login não funciona

Após mudar as anotações de ManagedBean para Named e o ViewScoped para javax.faces.view.ViewScoped, quando reinicia o servidor em vez de entrar na aba do login ele entra na pagina que estava, como por exemplo a do livro. Mas o login funciona quando o faz o logout da pagina.

4 respostas

o codigo do LoginBean está assim package br.com.caelum.livraria.bean; import java.io.Serializable; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.view.ViewScoped; import javax.inject.Named; import br.com.caelum.livraria.dao.UsuarioDao; import br.com.caelum.livraria.modelo.Usuario;

@Named @ViewScoped public class LoginBean implements Serializable {

private static final long serialVersionUID = 1L;

private Usuario usuario = new Usuario();

public Usuario getUsuario() {
    return usuario;
}

public String efetuaLogin() {
    System.out.println("fazendo login do usuario " + this.usuario.getEmail());

    FacesContext context = FacesContext.getCurrentInstance();
    boolean existe = new UsuarioDao().existe(this.usuario);
    if(existe ) {
        context.getExternalContext().getSessionMap().put("usuarioLogado", this.usuario);
        return "livro?faces-redirect=true";
    }

    context.getExternalContext().getFlash().setKeepMessages(true);
    context.addMessage(null, new FacesMessage("Usuário não encontrado"));

    return "login?faces-red.;irect=true";
}

public String deslogar() {
    FacesContext context = FacesContext.getCurrentInstance();
    context.getExternalContext().getSessionMap().remove("usuarioLogado");
    return "login?faces-redirect=true";
}

}

solução!

E quando da um F5 na pagina que esava em vez de entra na pagina do login ele entra na pagina que estava e aparece isso no console:

jul 05, 2019 3:33:31 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
jul 05, 2019 3:33:31 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
jul 05, 2019 3:33:31 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
jul 05, 2019 3:33:31 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
jul 05, 2019 3:33:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
jul 05, 2019 3:33:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
jul 05, 2019 3:33:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
jul 05, 2019 3:33:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/livrariadb?serverTimezone=UTC]
jul 05, 2019 3:33:32 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, autocommit=true, release_mode=auto}
jul 05, 2019 3:33:32 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
jul 05, 2019 3:33:32 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
jul 05, 2019 3:33:32 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.autor
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [nome, id, email]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.livro
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [preco, isbn, titulo, id, datalancamento]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.livro_autor
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [livro_id, autores_id]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: [fk9590997ad70c7e4a, fk9590997afa17418]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [fk9590997ad70c7e4a, fk9590997afa17418]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.usuario
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [senha, id, email]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
jul 05, 2019 3:33:32 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete

O problema é essa linha:

return "login?faces-red.;irect=true";

Substitui essa linha por: return "login?faces-redirect=true"; porém não mudou nada...

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software