Hi everybody, this is my first post on this forum, but, I read it alot while studying for my scjp exam and I found it really usefull. anyway here is my question: I am trying to forward a user to a html page, for that I use PageContext.forward in my jsp page and Tomcat throws a IllegalStateException. here is the jsp page: <%@ page language="java" %> <% pageContext.forward("/html/test.html"); %> From what I understand (not much!) is that the exception is thrown because the response buffer is flushed. So why is the buffer flushed? I haven't written to it. Althought in the generated java file, I can see that the directive :<%@ page language="java" %> causes a JspWriter.write call! And if I remove the directive the forward call works fine. If anyone knows what I'm doing wrong... Thanks in advance Dominic
As per Manning Book.... If the output is buffered, it is first cleared and then the request is forwarded to the other resources. If the output is not buffered and /or if the response is already committed by the forwarding resource, then a java.lang.illegalStateException is raised when we attempt to forward the request. Cheers, Vidya
If there is any new lines before and after your code , the converted class tries to write to JspWriter. Like out.write("\r\n"); According to spec, if the output is buffered , it must be cleared before forwarding. So just writing few lines to JspWriter is not a problem since it will be cleared. But make sure you do not have any newlines after your forward call . Also note that, the default value for "autoFlush" is true for <%@ page directive, which means if the written content is greater than the buffer size, then the output will be automatically commited. Also once a request is forwarded to another resource, it is said to be committed, so we should not try to write to JspWriter after that. So please try the following 1. Make sure there is no space / new lines after the forward call. 2. Try not to write anything before the forward call. 3. you can just write out.clear() to make sure the buffer is cleared , before the forward call.
Regards, Maha Anna [ December 15, 2002: Message edited by: Maha Annadurai ]