sending intermediate page via servlet

Discussion in 'Java' started by prabhat143@gmail.com, Jun 16, 2005.

  1. Guest

    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
    , Jun 16, 2005
    #1
    1. Advertising

  2. wrote:
    > 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>
    Aaron Isotton, Jun 16, 2005
    #2
    1. Advertising

  3. JScoobyCed Guest

    wrote:
    > 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

    --
    JSC
    JScoobyCed, Jun 16, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. N. Boucher
    Replies:
    0
    Views:
    3,075
    N. Boucher
    Nov 12, 2003
  2. circuit_breaker
    Replies:
    2
    Views:
    1,993
    Jack Jia
    Apr 4, 2004
  3. Houman
    Replies:
    0
    Views:
    410
    Houman
    Aug 12, 2004
  4. Lord Zoltar
    Replies:
    6
    Views:
    991
    Roedy Green
    Jul 8, 2009
  5. bhabs
    Replies:
    2
    Views:
    373
    Tad J McClellan
    Feb 13, 2008
Loading...

Share This Page