【发布时间】:2016-02-29 16:14:12
【问题描述】:
我试图在重定向到另一个页面之前在 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");
}
【问题讨论】: