} The explanation of example says that since the response header are always sent to the browser, so this method will throw IllegalStateException. When i run this code, it worked fine, except it didn't redirect to the url. If i comment the flush() , then it redirects me to cnn.com. I don't understand what is meant by committed response. When the above example will throw exception. Will appreciate your kind help.
Hi Salima The response is being committed when pw.flush() executes. ie A res.isCommitted() immediately afterwards will return true. Also, the res.sendRedirect("...") does throw an IllegalStateException. You can test this in a try...catch clause. So.... the Servlet side of things is working as expected. I'm guessing that the browser doesn't care about the exception and accepts the state of the response at the time it was committed. You would probably need to catch the exception and use sendError() to display a meaningful error on the browser. Hope this helps Mark.
Joined: Aug 15, 2002
Hello Mark, I tried working as you said. But it is not throwing an exception. Pls post your code so that i can understand. Thanks a lot!!! Salima
Joined: Feb 14, 2001
Salima After pw.flush(), code the following try...catch:
Your output should include: "An IllegalStateException occurred" Mark.
To continue on this question Can i set a Header say "name" as the header name and value is "MYNAME" in the response object and call the response.sendRedirect( url ) and Can i access the same header ( "name" ) in the redirected url? Thanks, AVNUS