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 have a problem while using response.sendRedirect() in my Jsp Page. Scenario: I have a Jsp page, which has static and dynamic includes In one of the dynamic include file, i am using response.sendRedirect() to redirect to another page. A runtime IllegalStateException is thrown in this case, as It says the response has already been committed. But if the response.sendRedirect() works fine when used directly in the main JSP Page. that too.. when the buffer size is increased Questions 1. What is the reason behind this exception. 2. what would be a better Solution this problem?
"sendRedirect() and sendError() methods will have the side effect of committing the response, if it has not already been committed, and terminating it. No further output to the client should be made by the servlet after these methods are called. If data is written to the response after these methods are called, the data is ignored." But if you have commited the response and have called sendRedirect() method, then that will result in IllegalStateException. You can use this method "response.isCommitted()" to check if response is already commited or not. Hope this helps.