This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Flush... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Flush..." Watch "Flush..." New topic
Author

Flush...

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
Hi,
I am inserting a bunch of records into the database and i know it takes a long time to insert. So i want something like wait message(Please wait...) to be viewed by the user rather than viewing just the blank page while its inserting records to the database.
I am using a servlet to do this. So just before the database insert statement i output this message saying (Please wait... ) on to the servletOutputStream and then flushing it.
out.println("Please wait . . .");
out.flush()
Soon after the insert is finished, i wan't that output to be displayed basically saying Num of successful inserts and Num of Error records.
My problem is, it's not outputting this "Please wait ..." message at the start of database inserts at all. This message is output along with the database status.
So my question is how to make this happen? For some reason flush() is not working here.
Any idea???
Appreciate your help,
Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Here's a few ideas:
1) When the request for the information is made, direct the request to a page that contains your "please wait..." message which in turn makes the actual request that will display the info. This way, while the info is being gathered, the intermediary page is being displayed.
2) An IE-only solution that I've used in the past when I knew that the web app was going to be used in an IE-only environment is a bit more complex and relies upon the page being a JSP.
I created a DIV with its display style initially set to visible. The visual style of this div made it look like a message box on the screen. The actual info was included into this page using a jsp:include directive. Once the included sub-page loaded, it invoked a javascript method that set the display mode of the "box" to invisible.
The effect is that the box would display immediately, and stay visible while the "sub-page" was loading. Once the sub-page loads, the "box" disappears.
This solution may be too fragile for general use. It relies upon IE-only capabilites (or at least Netscape 4.x can't change the page dynamically like this), and it relies upon the response output getting flushed to the browser before processing the jsp:include for the sub-page.
It worked fine in the environment in which it was deployed (controlled in-house web app, caucho resin container), but I'm not sure if I'd rely upon it in a broader environment. But I figured I'd relay this in case it's something you want to play with.
hth,
bear
[ April 08, 2002: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
What about sending your "Please wait..." with some HTML markup so the browser will know what to do with it? Like "<p>Please wait....</p>
Bill
Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
Thanks for your reply. It works fine now. I just did what William Brogden said.
Thanks again for your reply.
 
wood burning stoves
 
subject: Flush...
 
Similar Threads
Database Tuning for Performance
Problem facing with executebatch function
PrintWriter Problem?
Is this EJB 3 bulk insert/persist or this will reduce the network traffic?
java.sql.SQLException:Loss of significance