本文介绍了response.sendRedirect不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

response.sendRedirect()方法在我的程序中不起作用.

The method response.sendRedirect() is not working in my program.

代码通过并成功打印out.println("wrong user");,但是重定向到Google分页的页面无效.

The code go through and sucessfully print out.println("wrong user");, but the redirect to the google paged doesn't work.

String id="java";

try 
{
    query = "select Id from Users where Id= ?";
    ps  =Database.getConnection().prepareStatement(query);
    ps.setString(1, id);
    rs  =   ps.executeQuery();

    if(rs.next())
    {
        out.println(rs.getString(1));
    }
    else 
    {
        out.println("wrong user");
        response.sendRedirect("www.google.com");
    }
    rs.close();
}
catch(Exception e)
{
    //e.printStackTrace();
    System.out.print(e);
}   

有答案吗?

推荐答案

重定向后应return.

response.sendRedirect("http://www.google.com");
return;

调用sendRedirect()后不会自动返回.

It does not return automatically after calling sendRedirect().

这篇关于response.sendRedirect不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 11:53