另外:
如果在页面中可以同时运行两个response.sendRedirect页面,一样的出错例如:
<%@ page contentType="text/html;charset=GB2312" %><html>
<body>
<%
response.sendRedirect("index.html");
response.sendRedirect("index.html");
%></body>
</html>我用的是tomcat+jdk1.3

解决方案 »

  1.   

    这样试试:
    if(session.getValue("username")==null)||(session.getValue("roles")==null)) 
    {
    response.sendRedirect("index.html");
    }
      

  2.   

    jsp不允许同时存在两个response.sendRedirect("");
    因为此时它不知道该转向哪个所以报错所以你要修改代码
      

  3.   

    response中有一个状态位,重定向后状态置为True,不允许做第二次提交。
      

  4.   

    你需要知道的是,sendRedirect()方法执行后,并不是后面的程序就不继续执行了,所以,你需要添加return语句使得后面的程序终止执行。而你第一个程序满足两个条件,出错就不奇怪了。不过,反过来说,我使用Resin做服务器,执行下面的程序是没有任何错误的:
    <html>
    <head>
    <title>TEST</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF" text="#000000">
    <%
     response.sendRedirect("/");
     response.sendRedirect("/");
    %>
    </body>
    </html>