title: Display password error message in login page itself using servlet
body: <p>I want to display Username or password incorrect message in a particular <code>&lt;div&gt;</code> in the Login page.</p>
  
  <p>Here is my login.html code.</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
              &lt;form class="form-signin" method="POST" action="j_security_check"&gt;       
                  &lt;h2 class="form-signin-heading text-center" id="head"&gt;Login&lt;/h2&gt;
                  &lt;input type="text" class="form-control"  id="txtuser" name="j_username" placeholder="Username" required="required" /&gt;
              &lt;input type="password" class="form-control" id="txtuser" name="j_password" placeholder="Password" required="required"/&gt;
              &lt;div id="error"&gt;&lt;/div&gt;  
                  &lt;button class="btn btn-lg btn-default btn-block login1" id="txtuser" type="submit"&gt;&lt;span class="glyphicon glyphicon-log-in"&gt;&lt;/span&gt; Login&lt;/button&gt;   
              &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is my servlet code</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
  
    RequestDispatcher rd=request.getRequestDispatcher("/login.html");
  
    out.println("&lt;script&gt;");
    out.println("document.getElementById('error').innerText=Sorry UserName or Password Error");
    out.println("&lt;/script&gt;");
  
    rd.include(request, response);
  }
  </code></pre>
  
  <p>The message is not displaying in the <code>&lt;div id="error"&gt;</code> in login file</p>