Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

PROBLEM IN JSP

  Asked By: James    Date: May 27    Category: Java    Views: 898
  


Can any body tell what is the error in the code or why the error is coming
while executing these three lines of jsp code.

<%
out.println("This is the from first page");
out.flush();
%>
<jsp:forward page="sample2.jsp" />

I am getting the error like this:

java.io.IOException: Error: Attempt to clear a buffer that's already been
flushed
at org.apache.jasper.runtime.JspWriterImpl.clear(JspWriterImpl.java:180).

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Bethany Hughes     Answered On: May 27

By the out.flush method, http header have been written to the response output
stream,
and also your html output. In spite of these operations your code  try to perform
another
operation like page forwarding. I suppose that you want to use servlet chains
and one
output excepted, created by 2 servlet operation. You have to include your second
servlet response into first servlet. Dont forward your request. If you have to
select
forward or not to forward than please donot generate any response output before
your decision point in your code. This means, technically, dont send http page
headers
to your client if you want to forward client request another servlet.

i hope these are helpfull 4 u...

 
Answer #2    Answered By: Herbert Weaver     Answered On: May 27

I am not familiar with jsp  but just looking at the code  I can see one
possible problem. The out.flush() is probably causing your error. I took
this from the PrintStream class definition:

Optionally, a PrintStream can be created so as to flush automatically; this
means that the flush method is automatically invoked after a byte array is
written, one of the println methods is invoked, or a newline character or
byte ('\n') is written.

 
Answer #3    Answered By: Richie Smith     Answered On: May 27

You must not print anything using the out.println
and then forward to another jsp,
maybe if you have conditional forward then it would work,
once the response is commited which you have done by calling flush you cannot
forward.
if(some condition)
{
print something
}else
{
forward
}
would work

 
Answer #4    Answered By: Emma Brown     Answered On: May 27

then is there any way, so that i can display both the messages in the two jsp
pages by forwarding the request from one jsp  to other. Generally if i forward
from one jsp to other jsp file the message from the first jsp page is not
getting displayed while message in the second jsp file is getting displayed.

 
Answer #5    Answered By: Willie Gomez     Answered On: May 27

The problem  here is that you are trying to flush the buffer (out),
remove it and this will get flushed before the forward happens. Hope
this helps.

 
Didn't find what you were looking for? Find more on PROBLEM IN JSP Or get search suggestion and latest updates.




Tagged: