title: Alert inside a jsp page before redirect
body: <p>I am trying to make an alert appear on a JSP page prior to redirecting to another page. The alert appears if I don't redirect. But when I redirect, the alert doesn't appear at all and immediately redirects. Is there any way around this? </p>
  
  <p>Code: </p>
  
  <pre><code>if (rs.next()) {
                  ResultSet getHashedPw = st.executeQuery("select password from user where username='" + userid + "' LIMIT 1");
                  if(getHashedPw.next()){
                      String hashed = getHashedPw.getString(1);
                      if (BCrypt.checkpw(pwd, hashed)){
                          session.setAttribute("userid", userid);
                          response.sendRedirect("home.jsp");
                      }
                      else {
  
                          %&gt;
  
                              &lt;script&gt;
                                  alert("Error");
                              &lt;/script&gt;
  
                          &lt;%
  
                          response.sendRedirect("index.html");//works if I don't have this redirect. 
                      }
                  }
              }
              else {
                  response.sendRedirect("index.html");
              }
  </code></pre>