Hi, Does anybody know a way to call a JSP which displays information (eg please wait...) and at the same time automatically initiates a server program for background processing. When the server process has completed then control passes to the next web page.
Let us assume we have page1 , page2 and you are moving from page1 to page2 and in the mean while as this is a time taking process you want to show a please wait page.
Let us assume that the page with please wait is called "interim". now when you click on submit dont call the url for page2 but instead call the url for interim passing the same data that you would pass to page2 and let the interim page on page load call the page2... this will achieve your purpose.
One point though when I tried this out I found that the animated gif on the 'interim' page became a static gif. Is this a consequence of calling the server program immediately and is there any way around this.
HTTP is strictly request/response, so it's not a good idea to try to play games of that sort. A long-running process under a servlet will simply not return until the process is done and a thread spawned but not tracked will get lost.
What you can do is create a background thread and store it in your session, then set up the page to use the refresh meta-tag to poll the server periodically to see if the thread is finished.
This is a moderately complex task (usually takes me a day or so of coding to get going), so rather than explain in detail (and forget critical things), I'd recommend you search through similar messages in this forum and especially in the servlets forum.
Bjoke: A "Bully Joke". A Statement or action made with malicious intent - unless challenged. At which point it magically transforms into "I was just funnin'" or "What's the matter, can't take a joke?"
there is no thread being spawn here it is just a simple forward of request but that we introduced a interim page thats all we are doing..
and as far as the animation being lost i dont think this has got to do what youare doing... becasue alll you are doing is onload which means your page is already loaded...so dont think that cold be an isssue.
Browsers will not play GIF animations while they are loading the next page.
Tim's approach is your best bet for a robust way to deal with long-running processes.
The main problem with this appraoch is that if the user refreshes the parent page, all hell can break loose unless you have added guard code to prevent re-submission of the sub-request.
i also recommend Tim's advice, but i would use a MDB instead of a thread. Let the bean write some kind of flag that the refreshing page can consult until the work is done, then it can redirect to the next page. [ October 14, 2004: Message edited by: Pedro Gongora ]