aspose file tools*
The moose likes JSP and the fly likes buffer won't flush Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "buffer won Watch "buffer won New topic
Author

buffer won't flush

Jody Vandy
Greenhorn

Joined: Nov 13, 2003
Posts: 3
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

Joined: Jan 10, 2002
Posts: 61232
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Apr 15, 2002
Posts: 15
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

Joined: Jan 07, 1999
Posts: 6920
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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Yuri Sforza
Greenhorn

Joined: Apr 15, 2002
Posts: 15
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

Joined: Jan 07, 1999
Posts: 6920
I'm glad I was able to help. Now you just have to figure out how to work round this crazy limitation
 
Don't get me started about those stupid light bulbs.
 
subject: buffer won't flush