title: Set Ajax response on jsp not working
body: <p>Last few hours i am trying to solve this but i can not.I am sending ajax request using jquery and based on response i set data on jsp.actully i am checking login detail so if login fail it set error message on label problem is that error message is set for few second and removed i mean to say error message is set for few second i want that if login fails the message is set on label still user enter valid details</p>
  
  <p>thanks in advance</p>
  
  <p>Here is my code</p>
  
  <pre><code>         LoginDemo.jsp
  
        &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%&gt;
    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN  "http://www.w3.org/TR/html4/loose.dtd"&gt;
    &lt;html&gt;
     &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;link href="css/firstpage.css" rel="stylesheet" type="text/css" /&gt;&lt;!-- &lt;style&gt; --&gt;
      &lt;script src="js/jquery.min.js"&gt;&lt;/script&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
   &lt;script&gt;
     $(document).ready(function(){
     $("#submit").click(function(){   
    $.ajax({  
      type: "POST",
      url: "AddInspServlet",
      cache:false,
      data: { userid: $('#username').val(), password: $('#password').val(),btn:$('#submit').val() },
       success:function(data,textstaus){
       alert("success:"+data);     
       if(data == "no"){       
          alert( document.getElementById("error").innerHTML);     
           document.getElementById("error").innerHTML= "UserName OR Password is  incorrect";
          alert( document.getElementById("error").innerHTML);
  
    }else{
        location.href = 'Home.jsp';
  
    }
  
     },
     error:function(data){
      alert("error"+data);
       },  
      });
      });
      });
  
    &lt;/script&gt;
    &lt;/head&gt;
     &lt;body&gt;
     &lt;form id="login" name="Loginform" method="post"&gt;
       &lt;h1&gt;&lt;b&gt;Log In&lt;/b&gt;&lt;/h1&gt;
         &lt;fieldset id="inputs"&gt;
         &lt;input id="username" type="text" placeholder="Username" autofocus required&gt;   
         &lt;input id="password" type="password" placeholder="Password" required&gt;
      &lt;/fieldset&gt;
       &lt;fieldset id="actions"&gt;
        &lt;input type="submit" id="submit" value="login"&gt;
        &lt;a href=""&gt;Forgot your password?&lt;/a&gt;
       &lt;/fieldset&gt;
     &lt;label id="error" style="color: red;font: bolder; font-size: 18px;"&gt; 
     &lt;/label&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>      AddInspServlet
  </code></pre>
  
  <p>Here i m adding code which server executed and retrieve response</p>
  
  <pre><code>   if(btn.equals("login"))
       {
      System.out.println("***** login condition checking ******");
      String password =request.getParameter("password");
      UserVO v =op.loginCheck(username, password);
      if(password.equals(v.getPassword()))
      {
          System.out.println("inside true condition");
          HttpSession session = request.getSession();
          session.setAttribute("userid",v.getUser_id());
          session.setAttribute("username",v.getUsername());
          session.setAttribute("user", v.getFirst_name()+" "+v.getLast_name());
          session.setAttribute("roleid", v.getRole_id());
        //  response.sendRedirect("Home.jsp");
          System.out.println("submitting data success fully");
          out.print("yes");
          }
          else
          {
          System.out.println("false condition");
          out.print("no");
         }
       }
  </code></pre>