On Tue, 22 Jan 2002, Ronald Wildenberg wrote:

> Date: Tue, 22 Jan 2002 09:50:14 +0100
> From: Ronald Wildenberg <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Asynchronous messages from servlets
>
> Hi,
>
> I have the following problem. A simple form submits data
> to a servlet. The servlet sends a message via JMS to
> another application (in another JVM). Once the message
> has been sent, the 'service' method of the servlet ends.
> After a while, say five seconds, the other application would
> like to send back a response. How do I show this response
> to the user?
>
> Since the 'service' method has finished after sending the
> message, I have lost control over the output from the other
> application.
>
> What I need is a way to push the response to the browser. I
> would like the server to take the initiative in updating the browser
> window, not the user. Is this possible in any way?
>
> Thanks in advance,
> Ronald Wildenberg
>

There are two pieces to the answer for this kind of thing -- getting the
data back from the other JVM (I assume you are using asynchronous JMS
calls, right?), and displaying the data back to the user.

For the first step, doing an asynchronous JMS call in the other direction
(to a JMS receiver in the same JVM as Tomcat) could then receive the
results, and make them available as a servlet context or session
attribute.

For the second, I've seen people set up a page that uses the meta-refresh
capability in HTML to automatically keep sending a request every XX
seconds.  The servlet that receives this request will check to see if the
results are back yet - if they are, they are displayed, if they are not it
shows a "Request in Progress ... please wait" page with the meta refresh
tag.

The key thing is that you won't be able to respond on the original HTTP
request, since that has already been sent and your service() method has
returned.

Craig


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to