日期:2014-05-18  浏览次数:20685 次

页面为什么不跳转?
String answer=request.getParameter("Result");
  String sql="select * from Visit_All where Answer2='"+answer+"'";
  ResultSet rs = stmt.executeQuery(sql); //获取记录总数
if(rs.next()){ 
session.setAttribute("answer",rs.getString("Answer2"));
response.sendRedirect("../photo/photo_found.jsp");
}else{
out.print("<script language='javascript'>alert('答案错误!');location.href = 'password_visit.jsp';</script>");
}

这样写有什么错误么?页面为什么不跳转?
如果获得答案是错误的也执行ELSE的语句,但是当输入正确的答案时又重新回到了原来的页面,而不做跳转。


------解决方案--------------------
out.print(" <script language='javascript'>alert('答案错误!');location.href = 'password_visit.jsp'; </script>"); 
加个return;
------解决方案--------------------
探讨
out.print(" <script language='javascript'>alert('答案错误!');location.href = 'password_visit.jsp'; </script>");
加个return;

------解决方案--------------------
out.print(" <script language='javascript'>alert('答案错误!');location.href = 'password_visit.jsp'; </script>"); 
加个return;