How to show alert in a jsp from a servlet and then redirect to another jsp?

Posted by Xaul Omar Tobar on Stack Overflow See other posts from Stack Overflow or by Xaul Omar Tobar
Published on 2014-06-12T04:55:08Z Indexed on 2014/06/12 9:25 UTC
Read the original article Hit count: 177

Filed under:
|
|
|

I tried this but does not display the message only redirects login.jsp

<form method="post" action="Login_Servlet" >
  <input name="idUsuario" type="text"/>
  <input  name="password" type="password" />
  <button type="submit">Entrar</button>
</form>

Login_Servlet

response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String userid= request.getParameter("idUser");        
String password = request.getParameter("password");
Login_Service login_Service = new Login_Service();
boolean result = login_Servicio.aut(userid, password);
Usuario user = login_Servicio.getUsuariosByUsuario(userid);
    if(result == true){
       request.getSession().setAttribute("user", user);            
       response.sendRedirect("vistas/Inicio.jsp");
    }
     else{
       out.println("<script type=\"text/javascript\">");
       out.println("alert('User or password incorrect');");
       out.println("</script>");
       response.sendRedirect("index.jsp");    
    }

Is it possible to display a message like this? if so I'm doing wrong?

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp