Ok, I'm very new to JSP, so forgive me if this is a simple one. I'm working on fixing some errors in a page (one that I did not write myself unfortunately) and I keep getting a "Cannot forward because the response has already been committed" 500 Error.
I've narrowed it down to where I'm doing a forward() of my RequestDispatcher object, and I've read various topics on it that have told me this is happening because I've committed some output already. My question is how do I find where that is. Here's the code in the method that calls forward().
The code you posted is fine. As you have surmised, the problem is where in the JSP that code is called from. Any decisions regarding forwarding or redirection should take place at the top of the JSP before any template text or code that causes output to be generated . Actually, ideally, all this would have been taken care of in a servlet controller rather than the JSP itself, but that's probably not the structure you've been handed.
Once any template text or other output has been emitted, the response is considered comitted and you will get the result you are witnessing. [ September 18, 2004: Message edited by: Bear Bibeault ]
Ok, thats pretty much what I thought. Now my question is how the layout of the script might be screwing things up. Its set up for a account registration page, with one JSP script creating the 4 registration pages, with this login step being the final end of the script. The question is A: When do I have to worry aobut output and committing the page, after the final page is displayed? or some time earlier. Still working on figuring out exactly how all that works B: Is there a better way to do this? Granted I don't really want to reprogram the whole thing from scratch, but is there a better way of doing it than forward()?