你好 我这个jsp页面下alert弹窗无效,请问是什么原因呢。。

<body><%request.setCharacterEncoding("UTF-8");StringuserName=request.getParameter("us... <body>
<%
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("username");
String userPassword = request.getParameter("password");
if((userName!=null)&&(userName!="")&&(userPassword!=null)&&(userPassword!=""))
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lrm?useUnicode=true&characterEncoding=utf-8","miao","123");
String sql = "SELECT password FROM users WHERE username='" + userName + "'";
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(sql);

boolean flag=true;

while(rs.next()){
flag=false;
String password = rs.getString("password");
if(password.equals(userPassword))
{
String name = new String(userName);
session.setAttribute("name",name);
Integer count = (Integer)application.getAttribute("count");
ArrayList names = new ArrayList();
names.add(name);
application.setAttribute("names",names);
if(count==null){
count = new Integer(0);
}
count++;
application.setAttribute("count",count);
response.sendRedirect("main.jsp");
}
else
{
%>
<script language="javascript">alert("用户名或者密码输错啦~");</script>
<%
response.sendRedirect("index.jsp");
}
}
if(flag)
{

%>
<script language="javascript">alert("用户名或者密码输错啦~");</script>
<%
response.sendRedirect("index.jsp");

}
stat.close();
conn.close();
}
%>
</body>
展开
 我来答
loveandkissyou
2013-06-25 · TA获得超过2297个赞
知道大有可为答主
回答量:2332
采纳率:0%
帮助的人:2591万
展开全部
不是无效,是没来得及生效,就被重定向走了
改成:

<script language="javascript">alert("用户名或者密码输错啦~");location.href='index.jsp'</script>//让js处理alert和重定向
//response.sendRedirect("index.jsp");//不用服务器重定向
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式