This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Displaying progress when loading JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying progress when loading JSP" Watch "Displaying progress when loading JSP" New topic
Author

Displaying progress when loading JSP

Lijun An
Greenhorn

Joined: Feb 05, 2002
Posts: 15
Hi there,
How do I display progress on the page when a JSP is being loaded? The JSP page will process a lot of data before it is loaded into browser. I'd like to display a progress bar to tell the user to be patient.
Please comment.
Thanks,
Lijun
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The problem with JSPs (and HTTP in general) is there is a clear separation between code on the client server and code on the client.
That is, you cannot generally have code running on each end depending on each other. A request is sent to the server, it processes the request and a response is sent back to the client.
The best way I've encountered to do this is to use an intermediate 'Please Wait' page. Essentially the client sends a request to a 'fake processing servlet', this servlet returns a 'please wait' page and sends the original request to the real processing servlet.
The advantage here is that the 'Please wait' page is the one that is displayed while the long processing takes place.

DOM
Lijun An
Greenhorn

Joined: Feb 05, 2002
Posts: 15
Thanks a lot, DOM.
I understand that your approach is using a fake process servlet. That's fine. What if the process servlet/JSP is the JSP itself? How do I achieve displaying the progress to the client essentially in the same page?
Regards,
Lijun
Lijun An
Greenhorn

Joined: Feb 05, 2002
Posts: 15
Hi DOM,
Would you please tell me why the form 'auto' has two actions? I'm quite confused.
Thanks,
Lijun
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Oops, cut and paste error...
DOM
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Servlets and JSPs are expected to turn around rapidly. If they don't the user's browser will time out and the work gets lost. This is why long-running processes should be sent to back-end servers instead of being handled in the JSP code itself. Since HTTP does not support the back-end server volunteering any information, this means that you have to keep polling for information, and the easiest way to do that is by using a timed-refresh web page.
Once the data is complete and in the process of being transmitted back, the webapp is no longer involved. However in some web browsers, the browser itself will show how far along the actual transmission is.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
jQuery in Action, 2nd edition
 
subject: Displaying progress when loading JSP