• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display partial response

 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • 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?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks William,

I shall try that presently.
 
Atul Prabhu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • 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
 
Peter Bell
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic