tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Umesha Balasubramaniam <umesh...@goshen.edu>
Subject SendRedirect and IllegalStateException
Date Sat, 03 Apr 2004 14:35:14 GMT
Hi Everyone,

I am brushing up on my servlet programming after a long lay off. I was 
working through this book and came across the perils of using 
sendRedirect after commiting the response. My understanding according 
to the book and the 2.4 servlet api is that if you call the 
sendRedirect method after outputting something with the PrintWriter and 
flushing it should throw an Illegal exception, right? I want to know if 
anyone out there also noticed this or am I doing something wrong?
Tomcat version: 5.0.19
OS: Mac OS X 10.3.3
J2SDK:  1.4.2_03

My code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class RedirectException extends HttpServlet{

   public void doGet(HttpServletRequest request,
                       HttpServletResponse response) throws 
ServletException,
                                                       IOException {


       PrintWriter writer = response.getWriter();
       writer.println("<HTML>");
       writer.println("<BODY>");
       writer.println("Company News!!");
       writer.println("</BODY>");
       writer.println("</HTML>");
       writer.flush();
       response.sendRedirect("http://news.bbc.co.uk");




   }
}

What is happening is that the browser is displaying Company News!

Thanks,
Umesh


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message