You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Umesha Balasubramaniam <um...@goshen.edu> on 2004/04/03 16:35:14 UTC
SendRedirect and IllegalStateException
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
Re: SendRedirect and IllegalStateException
Posted by Tim Funk <fu...@joedog.org>.
It should display company news. And you should see in your logs an
IllegalStateException. (And the stack trace should contain the sendRedirect
method)
-Tim
Umesha Balasubramaniam wrote:
> 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!
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org