sending intermediate page via servlet

P

prabhat143

Hi,

I have a simple servlet that accepts some parameters and send those to
a bean. The bean does some calculation which takes a while.

What I would like to do is when servlet invokes the bean and while it's
waiting for bean to finish, I would like to display a simple html page
back to the user saying that calculation is currently in progress. Once
calculation is done, then I would like to send the user another page
with the result. How can I do this?

-parseParameters
-send message(html) to the user that calculation is being done
-invoke the bean to do the calculation
-when bean is done, send another message(html) to user with result.

Thanks,
Prabhat
 
A

Aaron Isotton

Hi,

I have a simple servlet that accepts some parameters and send those to
a bean. The bean does some calculation which takes a while.

What I would like to do is when servlet invokes the bean and while it's
waiting for bean to finish, I would like to display a simple html page
back to the user saying that calculation is currently in progress. Once
calculation is done, then I would like to send the user another page
with the result. How can I do this?

There is no clean solution to that, since HTTP doesn't allow you to
'send' anything more once you displayed your 'calculation in progress' page.

There is a workaround I know of using javascript; you write a function
to hide the 'your calculation is in progress' message, and call it in
the body onload tag (which is run only when the *entire* body tag is
loaded). Then, you serve the page with the message, wait until the
calculation is finished, and serve the rest. When the entire page is
delivered, the script is run and the 'in progress' message hidden.

Here's a sample page in pseudo-html and pseudo-javascript:

<html>
<head>
<script>
function calculationFinished() {
hide 'Your calculation is in progress' message
}
</script>
</head>

<body onload="calculationFinished()">

Your calculation is in progress. Please attend.

---- SERVE UNTIL HERE; CALCULATE, SERVE THE REST ----

Your calculation is finished.

</body>
</html>
 
J

JScoobyCed

Hi,

I have a simple servlet that accepts some parameters and send those to
a bean. The bean does some calculation which takes a while.

What I would like to do is when servlet invokes the bean and while it's
waiting for bean to finish, I would like to display a simple html page
back to the user saying that calculation is currently in progress. Once
calculation is done, then I would like to send the user another page
with the result. How can I do this?

-parseParameters
-send message(html) to the user that calculation is being done
-invoke the bean to do the calculation
-when bean is done, send another message(html) to user with result.

Thanks,
Prabhat

As Aaron mentioned, there is no *clean* way to do it. But there are
several turnaround. Have a look at Aaron's suggestion that looks good,
provided the browser repect the 'onload' condition (I remember some
browser that execute the 'onload' while displaying the page... long ago,
hope it is no more the case :) ).
There is the option to use an applet to listen for the server's 'end of
computation' message. It is a good control, as you can perform precise
user alert message in case of error/exception. But it is not the
cleanest as not all browsers support applet.
The other option is to use an off-screen frame (a frame of rows=0,
cols=0 or even a var my offscr = window.open() and
myoffscr.moveTo(-100,-100), but dirtier :) ) and in this frame submt a
form every second or 5 seconds (depending of your processing). When
done, this frame will manage to popup/display the "Computation finish"
message.

That's all that comes to me for now.
Good luck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top