Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重定向前jsp页面内的警报_Java_Jsp - Fatal编程技术网

Java 重定向前jsp页面内的警报

Java 重定向前jsp页面内的警报,java,jsp,Java,Jsp,我试图在重定向到另一个页面之前,在JSP页面上显示一个警报。如果我不重定向,将显示警报。但当我重定向时,警报根本不会出现,会立即重定向。这有什么办法吗 代码: if (rs.next()) { ResultSet getHashedPw = st.executeQuery("select password from user where username='" + userid + "' LIMIT 1"); if(getHashe

我试图在重定向到另一个页面之前,在JSP页面上显示一个警报。如果我不重定向,将显示警报。但当我重定向时,警报根本不会出现,会立即重定向。这有什么办法吗

代码:

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");
            }
if(rs.next()){
ResultSet getHashedPw=st.executeQuery(“从username=”+userid+“'LIMIT 1”的用户中选择密码”);
if(getHashedPw.next()){
String hashed=getHashedPw.getString(1);
if(BCrypt.checkpw(pwd,散列)){
session.setAttribute(“userid”,userid);
sendRedirect(“home.jsp”);
}
否则{
%>
警报(“错误”);

您可以在javascript中尝试重定向

<script>
   alert("Error");
   window.location= "index.html";
</script>

警报(“错误”);
window.location=“index.html”;

此外,我还鼓励使用JSTL。它有助于克服将java源代码添加到html中的问题,随着应用程序的发展,这可能会变得棘手且容易出错

这对于数据库驱动的Web应用程序尤其有用。JSTL语法一开始确实有一点学习曲线,但从长远来看是值得的,因为您将有一个可以重用的标记的repo