Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to get flush() and forward() working together?

Reply
Thread Tools

How to get flush() and forward() working together?

 
 
hiwa
Guest
Posts: n/a
 
      05-13-2004
In the doGet() method of a servlet, we do:

(1)out.println(simpleMessage);
(2)out.flush();
(3)Do a time consuming task
(4)When the task is finished, we call reqDispatcher.forward()
to display other resource.

The problem is as follows:

If we don't call flush(), simpleMessage doesn't get displayed
before going to other resource.

However, if we call flush(), reqDispatcher.forward() doesn't
work. The error message says "forward() not allowed after buffer
has committed."

If we use sendRedirect() instead of forward(), resulting error
message is the same.

Can't ther be a workaround for the problem?
 
Reply With Quote
 
 
 
 
Sunwest Technologies
Guest
Posts: n/a
 
      05-13-2004
Take a look at Web Progressor at http://www.SunwestTek.com/wp. It is
designed for scenario like this.

http://www.velocityreviews.com/forums/(E-Mail Removed) (hiwa) wrote in message news:<(E-Mail Removed). com>...
> In the doGet() method of a servlet, we do:
>
> (1)out.println(simpleMessage);
> (2)out.flush();
> (3)Do a time consuming task
> (4)When the task is finished, we call reqDispatcher.forward()
> to display other resource.
>
> The problem is as follows:
>
> If we don't call flush(), simpleMessage doesn't get displayed
> before going to other resource.
>
> However, if we call flush(), reqDispatcher.forward() doesn't
> work. The error message says "forward() not allowed after buffer
> has committed."
>
> If we use sendRedirect() instead of forward(), resulting error
> message is the same.
>
> Can't ther be a workaround for the problem?

 
Reply With Quote
 
 
 
 
Michiel Konstapel
Guest
Posts: n/a
 
      05-13-2004
On 13 May 2004 03:11:07 -0700, hiwa <(E-Mail Removed)> wrote:

> In the doGet() method of a servlet, we do:
>
> (1)out.println(simpleMessage);
> (2)out.flush();
> (3)Do a time consuming task
> (4)When the task is finished, we call reqDispatcher.forward()
> to display other resource.
>
> The problem is as follows:
>
> If we don't call flush(), simpleMessage doesn't get displayed
> before going to other resource.
>
> However, if we call flush(), reqDispatcher.forward() doesn't
> work. The error message says "forward() not allowed after buffer
> has committed."
>
> If we use sendRedirect() instead of forward(), resulting error
> message is the same.
>
> Can't ther be a workaround for the problem?


Nope. You have to pick one way of replying to the client's request.
Either you generate the reply yourself (out.println()) or you have someone
else do it (indirectly, by sending the client a redirect to another page,
or directly, by forwarding the request on the server side). You can't send
two replies to the same request.

What you can do is
(1) spawn a thread to do the time consuming task
(2) send the client a page that contains a refresh header, telling them
the "simple message"
(3) when the client comes back because of the refresh, check wether the
task has completed
(4a) if it hasn't, send them a "still busy" page, with another refresh
header
(4b) if it has, show the "other resource"

HTH,
Michiel
 
Reply With Quote
 
hiwa
Guest
Posts: n/a
 
      05-14-2004
Michiel Konstapel <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> On 13 May 2004 03:11:07 -0700, hiwa <(E-Mail Removed)> wrote:
>
> > In the doGet() method of a servlet, we do:
> >
> > (1)out.println(simpleMessage);
> > (2)out.flush();
> > (3)Do a time consuming task
> > (4)When the task is finished, we call reqDispatcher.forward()
> > to display other resource.
> >
> > The problem is as follows:
> >
> > If we don't call flush(), simpleMessage doesn't get displayed
> > before going to other resource.
> >
> > However, if we call flush(), reqDispatcher.forward() doesn't
> > work. The error message says "forward() not allowed after buffer
> > has committed."
> >
> > If we use sendRedirect() instead of forward(), resulting error
> > message is the same.
> >
> > Can't ther be a workaround for the problem?

>
> Nope. You have to pick one way of replying to the client's request.
> Either you generate the reply yourself (out.println()) or you have someone
> else do it (indirectly, by sending the client a redirect to another page,
> or directly, by forwarding the request on the server side). You can't send
> two replies to the same request.
>
> What you can do is
> (1) spawn a thread to do the time consuming task
> (2) send the client a page that contains a refresh header, telling them
> the "simple message"
> (3) when the client comes back because of the refresh, check wether the
> task has completed
> (4a) if it hasn't, send them a "still busy" page, with another refresh
> header
> (4b) if it has, show the "other resource"
>
> HTH,
> Michiel


Thanks.
Thread with page refresh did the work!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HttpWebRequest Post with ClientCertificates working in Debug and VS, but not working in IIS calebmeii@gmail.com ASP .Net 0 06-29-2007 04:55 PM
wifi not working on new hp, or not working after live update =?Utf-8?B?RHJhZ29ueA==?= Wireless Networking 1 10-01-2005 11:17 PM
freedom anti-virus working, but firewall and parental control not. working before. mmmarlee mcgarvey Computer Support 1 09-02-2004 05:28 PM
Runtime.exec() with env and working directory parameters is not working. Priyanka AGARWAL Java 9 05-25-2004 02:34 PM



Advertisments