Login screen - cannot log in a user, admin or user

Asked

Viewed 108 times

-4

users table;

create table usuario(
usuario_nome varchar(15) not null,
usuario_senha varchar(15) not null,
primary key (usuario_nome)
);

permission table;

create table permissao(
usuario_nome varchar(15) not null,
usuario_permissao varchar(15) not null,
primary key (usuario_nome, usuario_permissao),
foreign key (usuario_nome) references usuario(usuario_nome)
);

Inserts;

insert into usuario values('matheus','maithe');
insert into usuario values('maithe','matheus');
insert into permissao values('matheus','administrador');
insert into permissao values('maithe','usuario');

bean

@ManagedBean
public class UsuarioBean {

    private String usuario_nome;
    private String usuario_senha;

    public String login() {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

        try {
            request.login(this.usuario_nome, this.usuario_senha);
            return "dados?.redrect-true";
        } catch (ServletException ex) {

            return null;
        }


    }

    /**
     * @return the usuario_nome
     */
    public String getUsuario_nome() {
        return usuario_nome;
    }

    /**
     * @param usuario_nome the usuario_nome to set
     */
    public void setUsuario_nome(String usuario_nome) {
        this.usuario_nome = usuario_nome;
    }

    /**
     * @return the usuario_senha
     */
    public String getUsuario_senha() {
        return usuario_senha;
    }

    /**
     * @param usuario_senha the usuario_senha to set
     */
    public void setUsuario_senha(String usuario_senha) {
        this.usuario_senha = usuario_senha;
    }


}

web xml.

<login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/TelaDeLogin.xhtml</form-login-page>
            <form-error-page>/TelaDeLogin.xhtml</form-error-page>
        </form-login-config>
    </login-config>

    <security-role>
        <role-name>usuario</role-name>
    </security-role>

    <security-role>
        <role-name>administrador</role-name>
    </security-role>



    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Tela Usuario</web-resource-name>
            <url-pattern>/telausuario_1.xhtml</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>usuario</role-name>
        </auth-constraint>
    </security-constraint>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Administrador</web-resource-name>
            <url-pattern>/dados.xhtml</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>administrador</role-name>
        </auth-constraint>
    </security-constraint>

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/ProjetoGrandeRecife" >
    <Realm className="org.apache.catalina.realm.JDBCRealm"
           driverName="com.mysql.jdbc.Driver"
           connectionURL="jdbc:mysql://localhost/dp"
           connectionName="root" connectionPassword="root"
           userTable="usuario" userNameCol="usuario_nome" userCredCol="usuario_senha"
           userRoleTable="permissao" roleNameCol="usuario_permissao"/>
</Context>

login screen

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
<h:head>
        <title>Teste</title>
        <style type="text/css">
            body {background-color: #eeeeee; font-size: 12px}
        </style> 
    </h:head>
    <h:body>

        <div align="center">
            <p:layout style="min-width:1020px;max-width:1070px;min-height:640px">  
                <p:layoutUnit position="north" size="100">  
                    <h:graphicImage library="imagens" name="logo.png" width="1060" height="85"/>
                </p:layoutUnit>
                <p:layoutUnit position="center" size="800" rendered="true">  
                   <br/>
                   <br/>
                   <br/>
                   <br/>
                   <br/>
                   <br/>
                   <div id="msg1" style="background-color: #eeeeee; font-size: 30px">
                    GRANDE RECIFE CONSORCIO DE TRANSPORTE
                </div><br/>
                <div id="msg2">
                    Identifique-se por favor para utilizar
                    o sistema.
                </div><br/>
                <h:panelGrid columns="2">

                    <h:outputLabel value="Nome:" for="nome" style="background-color: navajowhite"/>
                    <h:inputText id="nome" style="background-color: #dddddd" label="Nome" value="#{usuarioBean.usuario_nome}"  required="true" />
                    <h:outputLabel value="Senha:" for="senha" style="background-color: navajowhite"/>
                    <h:inputSecret id="senha" style="background-color: #dddddd" label="Senha" value="#{usuarioBean.usuario_senha}" required="true" />
                </h:panelGrid><br/> 
                <h:commandButton action="#{usuarioBean.login()}" value="Entrar" style="position: relative;left: 78px;"/><br/>

             </p:layoutUnit>
            </p:layout>  
        </div>

    </h:body>
</html>

Upshot


Message from lcosta, Thursday, 13:34 28-Jul-2016 13:39:09.356 INFO [http-Apr-8080-exec-32] org.apache.Catalina.util.Lifecyclebase.start The start() method was called on Component [Standardengine[Catalina]. Standardhost[localhost]. Standardcontext[/Projetogrande Recife]] after start() had already been called. The Second call will be Ignored.

  • It’s not a mistake. It’s just an INFO.

1 answer

1

I’m not sure that’s it but,

Do not use underline (_) in variable names, you always start with lowercase letter and any other name that appears after you start with uppercase letter. Example: nounUsuario

So this may create confusion with the names of the methods getUsuario_nome() would become usuarioNome, getUsuarioNome() and setUsuarioNome(). Make these adjustments and see if the problem persists.

EDIT:

Complementing the reply, the message you are receiving is not an ERROR but an INFO.

This Exception at shutdown Happens only if examples webapp was correct when Tomcat Started, but was Broken Afterwards. If it was already Broken at startup time, Nothing Happens.

https://issues.apache.org/bugzilla/show_bug.cgi?id=51610 -Maybe it help.

This exception only happens if the webapp was correct in the Tomcat startup but was corrupted later. If he were corrupted already at first nothing would happen.

Check the link

  • People excuse the end of the message disregard,ended up giving a c Ctrl unintentionally, here in another document.

  • The result is this.

  • 28-Jul-2016 13:39:09.356 INFO [http-Apr-8080-exec-32] org.apache.Catalina.util.Lifecyclebase.start The start() method was called on Component [Standardengine[Catalina]. Standardhost[localhost]. Standardcontext[/Projetogranderecife]] after start() had already been called. The Second call will be Ignored.

  • Please add this to the question.

  • People changed the variables even more unsuccessfully,some different tip.

  • All the more how I can fix this,...

  • I did a search and saw that the message you are receiving is an INFO and not an ERROR.

  • Yes more what I can do to solve this,I’ve seen several tutorials and I’m doing according to study,more may be that there is something I can’t find.

  • What version of Tomcat are you using?

  • Version 8 of Tomcat

  • I just noticed that the tag is missing <form></form> on your login screen. No?

  • I can’t access the chat from where I am unfortunately..

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.