response.sendRedirect在哪都可以,调试一下你的程序吧,看看status是否得到值了,看看程序是否在执行到response.sendRedirect之前就出错退出了。

解决方案 »

  1.   

    可能是你的查询出错,rs为null.response.sendRedirect在任何地方都有效,不过前提是不要已经有执行的内容返回到客户(被fush())。
      

  2.   

    javahui(阶级斗争要年年讲,月月讲,天天讲。)
    是的,我希望当查询为空时也要跳转,可以实现吗?
      

  3.   

    fft123() 
    我给status赋过初值0了 。
      

  4.   

    if(!rs.next())
    {
          ...//没有记录跳转
    }
    else//有记录
    {
                       while(rs.next())
    {
    status=rs.getInt("Status");
    }
    if (status == 1)
    {
    response.sendRedirect("../error_page.jsp");
    }
    else
    {
    response.sendRedirect("../success_page.jsp");
    }
    .......
    }
      

  5.   

    直接写rs==null行不行??if(rs==null)
    {
          ...//没有记录跳转
    }
      

  6.   

    ??
    什么意思?到什么地方没法跳?设置断点观察一下程序走到哪里了。eg:if(!rs.next())
    {
          out.println("<script>alert('1 here!');history.back();</Script>");//没有记录
          return;
    }
    if (status == 1)
    {
    //response.sendRedirect("../error_page.jsp");
             out.println("<script>alert('2 here!');history.back();</Script>");
             return;
    }
      

  7.   

    // userid 后面的值用单引号引起来。
            String sql = "select Status from User where userid = '1003'"         ResultSet rs = stmt.executeQuery(sql);
                     if (rs != null) {
                         while(rs.next()){ status=rs.getInt("Status");
          }
                         if (status == 1){
    response.sendRedirect("../error_page.jsp");
       } else {
    response.sendRedirect("../success_page.jsp");
       }
                      } esle {
                          response.sendRedirect("../.....jsp");
                      }