I can not put the servlet value in the JSP page

0

I am trying to validate the login and password of the user, in that if not enter the fields of login and password will appear a message in the screen "Please fill in the fields of login or password" or in case the user type the user or Incorrect password will show a message on the screen "Incorrect login or password" but it does not show messages.

DAO Class

public Cliente validacaoLogin(String login,String senha){
     Cliente  cli = new Cliente();
    try {
        con = Conecta.conexao();
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ClienteDAO.class.getName()).log(Level.SEVERE, null, ex);
    }



//String sql="Select cli_nome  from tb_cliente where cli_login=? and cli_senha=? ";
String sql="Select cli_nome,cli_login,cli_senha  from tb_cliente where cli_login= '" + login + "' and cli_senha= '" + senha + "'";

    try {
        pst = con.prepareStatement(sql);
           rs= pst.executeQuery();

        while(rs.next()){

              cli.setLogin(rs.getString("cli_login"));
              cli.setSenha(rs.getString("cli_senha"));


          cli.setNome(rs.getString("cli_nome"));

        }

        return cli;
    } catch (Exception e) {
        JOptionPane.showConfirmDialog(null,e);
        return null;
    }

} 

Servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
   // processRequest(request, response);
   String vazio="Por favor preencha os campos de login ou senha"; 
   String incorretos="Login ou senha incorretos"; 

    String login = request.getParameter("login");
      String senha = request.getParameter("senha");

        Cliente cli= new Cliente();
           LoginDAO login2= new  LoginDAO();


Cliente login_validacao=login2.validacaoLogin(login,senha);


 if(login_validacao.getLogin()==null && login_validacao.getSenha()==null){
  request.setAttribute("vazio", vazio); 

  }
else if(login_validacao.getLogin().equals(request.getParameter("login")) & login_validacao.getSenha().equals((request.getParameter("senha")))){

 RequestDispatcher rd=request.getRequestDispatcher("/index.jsp");
 rd.forward(request, response);
 }
 else{
request.setAttribute("incorreto", incorretos); 
   }

}

JSP Page

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="js/jquery-1.12.0.min.js" type="text/javascript"></script>
    <script src="js/jquery.maskedinput.js" type="text/javascript"></script>
    <script src="js/jquery.maskedinput.min.js" type="text/javascript">
    </script>

    <script src="bootstrap/bootstrap.min.js" type="text/javascript">
     </script>
    <script src="bootstrap/bootstrap.js" type="text/javascript"></script>
    <link rel="stylesheet" href="bootstrap/bootstrap.css">
    <link rel="stylesheet" href="css/css.css" type="text/css">
    <link rel="stylesheet" href="css/font-awesome.min.css" type="text/css"/>
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-
  awesome.min.css" rel="stylesheet">
    <title>JSP Page</title>
</head>

<body>
  <div class="login-form">

    <div class="row">
    <div class="col-6 col-md-4"></div>
     <div class="col-6 col-md-4">
     <h2 id="AcesseConta"><span>Acesse sua Conta</span></h2>
     <label for="vazio_resposta">${vazio.vazio}</label>
      <label for="validacao">${incorreto.incorretos}</label>
     </div>
    </div>

    <div class="row">
     <div class="col-6 col-md-4"></div>   
         <div class="col-6 col-md-4">
     Login:<input type="text" id="login" name="login" ><br/><br/>
     Senha:<input type="text" id="senha" name="senha" ><br/>
     <a href="">Não é cadastrado?Cadastre-se</a><br/><br/>
     </div>

    </div>

    <div class="row">
     <div class="col-6 col-md-4"></div>   
         <div class="col-6 col-md-4">
              <div id="teste"></div>  
     <button type="button" onclick="login()" >Entrar</button>  <button 
  type="button" onclick="" >Esqueceu a Senha?</button> 
     </div>

    </div>
     </div>
</body>

    
asked by anonymous 22.09.2017 / 20:40

1 answer

0

Try to set the message in the response instead of the request.

response.setHeader("vazio", vazio);

And on the page you can leave it like this:

<label for="vazio_resposta">${vazio}</label>
    
22.09.2017 / 22:29