script无法弹出alert窗口
<%
request.setCharacterEncoding("gb2312");
String userName=request.getParameter("name");
String userPass=request.getParameter("password");
String sql ="select * from tb_user where username='"+userName+"' and password='"+userPass+"'";
ResultSet rs=db.querySQL(sql);
session.setAttribute("islog",new String("0"));
if(!rs.next()){
out.println("<script language='javascript'>");
out.println("alert('用户名或密码错误');");
out.println("</script>");
response.sendRedirect("index.jsp");
}else{
session.setAttribute("name",rs.getString(2));
session.setAttribute("password",rs.getString(3));
session.setAttribute("islog",new String("1"));
session.setAttribute("lastLogTime",rs.getString(4));
String logTime = calendar.getDate();
int id=rs.getInt(1);
String dateSql = "update tb_user set userLastLogTime='"+logTime+"'where ID="+id;
db.updateSQL(dateSql);
db.closeAll(rs,null,null);
out.println("<script language='javascript'>");
out.println("alert('登入成功');");
out.println("</script>");
request.getRequestDispatcher("chat.jsp").forward(request,response);
}
%>
请问alert无法弹出窗口,是什么原因?
------解决方案--------------------response.sendRedirect("index.jsp");
request.getRequestDispatcher("chat.jsp").forward(request,response);
页面都跳转了,都不是out输出的page了,当然没用了
------解决方案--------------------
out.println("<script language='javascript'>");
out.println("alert('用户名或密码错误');");
out.println("</script>");
response.sendRedirect("index.jsp");
改成下面的看看
out.println("<script language='javascript'>");
out.println("alert('用户名或密码错误');");
out.println("window.location.href='index.jsp'");
out.println("</script>");
这样也能达成效果。