----------
From: Wilfried Geis willi@itm-research.de
To: Java Apache Users java-apache-users@list.working-dogs.com
Subject: Re: Servlet/web programming - user feedback during computations
Date: Tue, Aug 24, 1999, 5:35 AM
Andy,
you need to use the content-type: multipart/x-mixed-replace
I've rewritten your example so that it works. check it out:
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("multipart/x-mixed-replace;boundary=\"boundary\"");
ServletOutputStream out = res.getOutputStream();
out.println("--boundary");
out.println("Content-Type: text/html\r");
out.println("\r");
out.println("Awaiting query results, please wait ...br\n");
out.flush();
try {
Thread.sleep(3000);
} catch (Exception e) {
out.println("interrupted: " + e);
}
out.println("--boundary");
out.println("Content-Type: text/html\r");
out.println("\r");
out.println("This is the end");
out.println("--boundary--");
out.flush();
}
Andy Jefferson wrote:
> -----------------------------
> Please read the FAQ!
> http://java.apache.org/faq/
> -----------------------------
>
> Hi,
>
> not sure of the best place to ask this one. Anyway, I've got a servlet
> (running on Apache, with JServ 1.0 for what it matters) doing DB
> accesses, and some of these accesses take a while to complete. I want to
> give the user feedback while the DB query is being performed - something
> along the lines of
>
> 'Awaiting query results. Please wait ...'
>
> and then when the results are returned, repopulate the same frame with
> the results. I've heard that I can do this with MIME, by setting the
> ContentType to 'multipart/mixed', and sending several 'parts', but cant
> get it to work properly.
>
> For example, if I do
>
> response.setContentType("multipart/mixed;boundary=my_identifier");
> ServletOutputStream out=response.getOutputStream();
> out.println("--my_identifier");
> out.println("Content-Type: text/html\r");
> out.println("\r");
> out.println("Awaiting query results, please wait ...");
> out.flush();
>
> <... perform DB query ...>
>
> out.println(--my_identifier");
> out.println("Content-Type: text/html\r");
> out.println("\r");
> <... DB results ...>
> out.println("--my_identifier--");
> out.flush();
>
> But I get the whole text including the MIME separators displayed by the
> browser (Netscape 4.*). Has anyone got a working example ?, or a
> reference I can look at ?
>
> TIA
> --
> Andy
> |