Joona Palaste wrote:
> Several people on this list have mentioned the method flush() of the
> PrintWriter belonging to a HttpServlet's HttpResponse. This seems to work
> right
> only on plain text files, not markup languages like HTML or WML (Wireless
> Markup Language).
> Suppose I have this kind of code in my servlet's doGet() method...
>
> out.println("Please wait...");
> out.flush();
> long t=System.currentTimeMillis();
> while (System.currentTimeMillis()<t+10000); // wait 10 seconds
> out.println("Finished.");
> out.close();
>
> If I have set the content-type to text/plain, it works like it should, the
> text
> "Please wait..." arrives right away and after 10 seconds, the text "Finished."
> arrives. However, if I change the content-type to text/html, the browser just
> waits 10 seconds, and then both lines arrive. It is the same with WML. As the
> services I'm developing need markup languages, not plain text, I need some way
> to output HTML or WML content with the flush() method, or a similar method. Is
> there any way to do this?
>
> Joona Palaste
>
This turns out to be a "feature" of the way that browsers are implemented.
When a browser receives an HTML page, it dynamically decides how to format the
text to your screen. If you send something like this:
<p>
This is
a paragraph
split across
multiple lines.
</p>
the browser will, if your screen is wide enough, format this entire paragraph on
a single line. But the key point is that the browser could not format this
paragraph until it had all the text in it.
The problem in your case is that, after it receives "Please wait ....", the
browser does not know if you are going to add any more text to this paragraph, so
it cannot be formatted yet. Try adding a "<br>" or "<hr>" after this text, and
see if it works better.
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html