Message on the JSP Servlet page

0

I am developing a JSP and Servlet login in which it does the validation of the fields if they are filled and certain but when redirecting to login page it does not display the message of Please fill in the fields of login or password or Incorrect login or password .

JSP Page

 <div class="cadastrado">
                <h2 id="AcesseConta"><span class="fa fa-user"> Já sou Cadastrado</span></h2>


                    <p  style="color:red;" align="center"><c:out value="${vazio}"/></p>



                <c:if test="${!empty incorretos}">
                    <p  style="color:red;" align="center">${param.incorretos}</p><br/>
                </c:if> 


                <form action="Login" method="POST"  >

                      <div class="componentes_login">Login:<input type="text" id="login" name="login" ></div><br/>
                    <div class="componentes_login"> Senha:<input type="password" id="senha" name="senha" ></div><br/>

                    <div class="componentes_login"><button type="submit" class="btn_login">Entrar</button>  <button type="submit" onclick="" class="btn_login" >Esqueceu a Senha?</button> </div>
                    <div class="margin_baixo"></div>

                </form>
            </div>

Servlet

        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

     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);

 RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");

 rd.forward(request, response);

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

  HttpSession session=request.getSession();

  String nome= (String) login_validacao.getNome();

  session.setAttribute("nome",nome);

  request.setAttribute("nome",session.getAttribute(nome));


  RequestDispatcher rd=request.getRequestDispatcher("/index.jsp");
  rd.forward(request, response);
  }

  else{

 request.setAttribute("incorreto", incorretos); 

 RequestDispatcher rd=request.getRequestDispatcher("/login.jsp");
 rd.forward(request, response);

  }
}
    
asked by anonymous 28.10.2017 / 22:41

0 answers