Message on JSP Servlet page

Asked

Viewed 234 times

0

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

Page JSP

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

  }
}
  • try to use requestScope.incorretos in both fields in jsp

  • didn’t work Bruno Morales

No answers

Browser other questions tagged

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