Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

buffer won't flush

 
Jody Vandy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to print out a message while my page is doing a lengthy process. I've tries many method, all of which will not work because I can't flush the buffer.
Ex:
<html><head>
<title>Please Wait...</title>
</head><body>
<br><br><br>
<center>Loading data.<br>
Please wait.</center>
<%
response.flushBuffer();
int x = 100000;
while(x>0){
x--;
}
%>
Finished with page.
</BODY>
</HTML>
If I understand flushBuffer() correctly, then the "please wait" message should print immediately but it doesn't. The entire page gets loaded after the while loop terminates.

BTW- I'm running it on a tomcat4 server.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to second guess when flushing will occur in order to implement this kind of feature will lead you down a road of pain and sadness.
If you must implement this feature you'd be better off trying one of the following tactics:
1) Your first page submits to a 'please wait' page which in turn submits the 'real' function.
or
2) Your first page has an invisible floating div that is hidden until the submit button is pressed, when Javascript is used to reveal it until the page gets replaced with the next one.
bear
[ November 13, 2003: Message edited by: Bear Bibeault ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. The other problem you are likely to run into is that even if the browser receives the data, there is no guarantee that it will display it. For example, if you have a HTML table around the whole page for formatting, some browsers will require you to close this table before trying to render it on the screen.
The behaviour would be annoyingly browser dependent and will just make you lose hair until you try one of the solutions suggested by Bear.
Dave
 
Yuri Sforza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found that flushing just response is not enough,
but it works OK when using combination:

Another thing I have found out by hard experience
is that if you currently have less than 256 bytes
in the buffer it will not be flushed. So I wander:
does spec say anything about such behaviour
(implementation-dependent or like?) or is it a bug?
I am using Websphere 5 server which comes with WSAD.
--
Y. Sforza
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have found out by hard experience
is that if you currently have less than 256 bytes
in the buffer it will not be flushed.

Are you sure this isn't a due to a browser problem? I've seen several bits of code where the author added extra characters to short output to bring it over some threshold, because IE can be reluctant to display very short pages.
 
Yuri Sforza
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Carver:
Are you sure this isn't a due to a browser problem? I've seen several bits of code where the author added extra characters to short output to bring it over some threshold, because IE can be reluctant to display very short pages.

Well, never can I be sure with such things. I have run another simple test
on Tomcat and it worked. So it looked like the problem is more probably
located at web-container. Though it was different jsp than original
one. To clarify situation more I have checked the behaviour by connecting
to server through telnet (do not have other than IE browser).
And yes, you are right -- the output is seen to be flushed correctly.
So it is IE to blame.
[ December 11, 2003: Message edited by: Yuri Sforza ]
[ December 11, 2003: Message edited by: Yuri Sforza ]
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad I was able to help. Now you just have to figure out how to work round this crazy limitation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic