posted 15 years ago
You cannot change the response anymore when it is already been committed (the headers are been sent to the client). A response is committed when one or more of the following conditions is met:
1) You have written more than 8KB (at least, the default buffer size) to the response, which implicitly invokes flush().
2) You have explicitly invoked flush() on the outputstream of the response after written a small amount of data to it.
3) You have invoked RequestDispatcher#forward() with it.
4) You have already invoked another sendRedirect() on it.
A sendRedirect() require a change of the response headers. So if you call sendRedirect() on a response which is already committed, you will get this exception.
Avoiding it is quite simple: write proper code.