IllegalStateException异常
如下:
String sql = "select uName,uPassword from login_user" ;
try {
pstmt = con.prepareStatement(sql) ;
rs = pstmt.executeQuery() ;
while(rs.next()){
uName = rs.getString("uName") ;
uPassword = rs.getString("uPassword") ;
if(userName.equals(uName)&&userPassword.equals(uPassword)){
request.getSession().setAttribute("name", userName) ;
request.getRequestDispatcher("login_success.jsp").forward(request, response) ;
}else{
这句错误 request.getRequestDispatcher("index.jsp").forward(request, response) ;
}
}
} catch (
SQLException e) {}
出现在else的错误,异常为IllegalStateException我认为是else跳转打破了while循环,因为while还没判断是否还有下一个结果集,但是为什么我把else的转向给注释了,他就不出错了呢,他还是打破while循环了啊
------解决方案--------------------
if(userName.equals(uName)&&userPassword.equals(uPassword)){
request.getSession().setAttribute("name", userName) ;
request.getRequestDispatcher("login_success.jsp").forward(request, response) ;
return;
}else{
request.getRequestDispatcher("index.jsp").forward(request, response) ;
return;
}
while循环到else里面 第一次跳转了 如果第二次循环再跳转就会出这个错误