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? 

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 {

                        %>

                            <script>
                                alert("Error");
                            </script>

                        <%

                        response.sendRedirect("index.html");//works if I don't have this redirect. 
                    }
                }
            }
            else {
                response.sendRedirect("index.html");
            }

```