这是一段验证用户的代码,请问不知为什么当用户不存在的时候总有"[Microsoft][ODBC 驱动程序管理器] 无效的游标状态"这样的错误,如果这里把if...else...配套使用,则不会出错.很显然当用户不存在的时候运行到window.top.location='index.jsp',页面跳转以后,这个页的下面程序也是执行的.请问一下想要当用户不存在的时候,运行到window.top.location='index.jsp',这个页的下面程序不被执行,请问一下这个功能怎样实现.谢谢!
(我想把这代码上半部分制作成一个 单独 的jsp文件中,然后在其它页中插入这个文件,以此来验证用户的合法性,所以这个页面不想配套使用if...else...)<%
String username=(String)session.getAttribute("username");
Connection con=dbconnection.getConnection();
String sql="select * from user where username=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1,username);
ResultSet rs=pstmt.executeQuery();
if(!rs.next()){
out.println("<script language='javascript'>alert('请输入用户名!');window.top.location='index.jsp';</script>");
}String depart=rs.getString(3));
...........
...........%>
(我想把这代码上半部分制作成一个 单独 的jsp文件中,然后在其它页中插入这个文件,以此来验证用户的合法性,所以这个页面不想配套使用if...else...)<%
String username=(String)session.getAttribute("username");
Connection con=dbconnection.getConnection();
String sql="select * from user where username=?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1,username);
ResultSet rs=pstmt.executeQuery();
if(!rs.next()){
out.println("<script language='javascript'>alert('请输入用户名!');window.top.location='index.jsp';</script>");
}String depart=rs.getString(3));
...........
...........%>
if(!rs.next()){
out.println("<script language='javascript'>alert('请输入用户名!');<jsp:forward page='index.jsp'/>">
}这样试试~