• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display partial response

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I have seen a web page display part of the html response while the server is still returning information. Is there a way of coding your servlet so that for a given page part of the html response can be displayed before the servlet is done writting to the output stream?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At any point, you can do a out.flush() - that should send any characters currently in the output buffer. Of course, whether or not the browser display will show any activity depends on the browser and the HTML you are sending. I think a plain <p> paragraph will get displayed but if you are building a table the browser may wait until the table is finished to show it.
Bill
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks William,

I shall try that presently.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,

Could u tell me the reason why response.sendRedirect() does not work after using out.flush().

----
Atul
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Flushing the output buffer for the first time sends the HTTP headers. Since redirect involves setting a header line, if you do it after the headers have been sent you get a IllegalStateException.
Bill
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another option is to create a task for the long running action.

Assign it an id.

The task writes its progress to a session variable keyed by that id.

Send the user to a page with that id as a parameter.

That page loads the progress from the session based on the id. The page reloads itself (using Javascript or a meta refresh tag) until the task is complete.
 
Atul Prabhu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Willaim,

Here are two cases :

Case 1:

out.println("Wait....");
out.flush();
response.sendRedirect("next.html");


In this case I get a Illegal State Exception (its right w.r.t Willaim)

Case 2:

out.println("Wait...");
response.sendRedirect("next.html");

In this case I dont get any exception.It redirects to the next page.
Doesn't out.println() stmt set the HTTPHeaders..?

I am a bit confused. Do you have any good tutorial which explains this concept in detail?

--
Atul
 
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic