title: showing error message(invalid name or password) in same jsp page is not working
body: <p>i have two jsp file <strong>index.jsp</strong> and <strong>login.jsp</strong> and <strong>profile.jsp</strong>.
  here index.jsp has two text field name and password. </p>
  
  <p>When I give right name and password login shows successful and go to <strong>success.jsp</strong> but when i give wrong password or name i want that an error message will show in same index page that is "invalid name or pass". my code is not working <strong>login.jsp</strong> is used for username and password authentication..please help me to solve this .</p>
  
  <p>I have searched about RequestDispatcher but it is used in servlet class.but i want to do it in my jsp file.my code</p>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;JSP Example&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
     &lt;form method="post" action="login.jsp"&gt;
          &lt;center&gt;
          &lt;table border="1" width="30%" cellpadding="3"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th colspan="2" align ="left"&gt;Login Here&lt;/th&gt;&lt;h5&gt;&lt;%=request.getAttribute("errorMessage") %&gt;&lt;/h5&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td&gt;User Name&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="uname" value="" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Password&lt;/td&gt;
                      &lt;td&gt;&lt;input type="password" name="pass" value="" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;input type="submit" value="Login" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="reset" value="Reset" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;Yet Not Registered!! &lt;a href="reg.jsp"&gt;Register Here&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;/center&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>login.jsp</strong></p>
  
  <pre><code>&lt;%@ page import ="java.sql.*" %&gt;
      &lt;%
      String userid = request.getParameter("uname");    
      String pwd = request.getParameter("pass");
      Class.forName("org.postgresql.Driver");
      Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres", "root");
      Statement st = con.createStatement();
      ResultSet rs;
      rs = st.executeQuery("select * from member where uname='" + userid + "' and pass='" + pwd + "'");
      if (rs.next()) {
          session.setAttribute("userid", userid);
          //out.println("welcome " + userid);
          //out.println("&lt;a href='logout.jsp'&gt;Log out&lt;/a&gt;");
          response.sendRedirect("success.jsp");
      } else {
          //out.println("Invalid password &lt;a href='index.jsp'&gt;try again&lt;/a&gt;");
          request.setAttribute("errorMessage", "Invalid user or password");
          response.sendRedirect("index.jsp");
               }
      %&gt;
  </code></pre>