This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am working on a application where there is a file which contains a for loop where the i value checks for 5 values, but when the loop is running and when i==3 , the page is redirected automatically, at that time the system throws an java.lang.IllegalStateException.how can i overcome this?.
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.