• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

About flush() in Servlet

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to send data partially to the browser. So I use flush() method in PrintWriter Object. This will work fine when the data to be send is more than some 100 characters. But if it 5-10 chars the flush is not sending the data at that moment.



Here if stringToPrint conatains more than 100 characters it is sending the data at that moment itself. But otherwise it is sending it later.

Any Idea about his.
Thanjs in Advace.


[BSouther: Added UBB CODE tags]
[ March 21, 2007: Message edited by: Ben Souther ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect that the servlet is indeed flushing the output stream.
If this is the first time it is flushed, the buffer will send the response headers plus whatever you have written.
However, on the web browser side, the browser can decide that it does not have enough to even try to show something and will just wait for more. Perhaps you should ensure that what you send makes good HTML sense.

Bill
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to meet the requirement. By using any header entry or by setting minimum cache or buffer or like that.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is your requirement? If you need to progressively disclose parts of the page, you'll need to use a means that gives you more control over the process. flush() was never meant for that purpose.
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I want to progressively display the items. Like,

Contacting Vendor................
Validating CreditCard............
Calculating Amount..............
Retriving Amount...............
.............
..............

Here, each process take some time(about 20 sec)

In what way I can do this easily.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it that these things are legitimately taking 20 seconds each or do you just want it to appear that they do?
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, those process take that much time. So I need to show the progress to the user.
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Any simple way for doing this?
 
Jose Mon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Any simple way for doing this?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
20 seconds is a long time to hold a browser connection open.

An alternate technique would be to spawn a new thread for your long running process, and return a status page to the user right away.
That page could refresh every n seconds until the process has finished.

I have an example app that does just this at:
http://simple.souther.us/not-so-simple.html
Look at LongRunningProcess.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic