This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

streaming output

 
shankar vembu
Ranch Hand
Posts: 309
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just trying to test whether i can send streaming output to the client from my servlet. So i wrote the following code:

This is actually taken from a javaworld article.
Now the flush is not working for me. I am using IE. I expect my browser to display countdown number every sec. But what I get is only the final response with all the numbers. So is this not the right way to achive something like a streaming output???
Regards.
 
Sean Sullivan
Ranch Hand
Posts: 427
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What servlet engine ( or app server) are you using?
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletResponse.html
Have you tried calling flushBuffer() on the HttpServletResponse object?
-Sean
 
shankar vembu
Ranch Hand
Posts: 309
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sean Sullivan:
What servlet engine ( or app server) are you using?
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletResponse.html
Have you tried calling flushBuffer() on the HttpServletResponse object?
-Sean

tomcat. tried flushing the buffer, but it wont work either
 
shankar vembu
Ranch Hand
Posts: 309
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any pointers. i am still stuck with this issue. BTW i guess the same principle is being used in pushlets, right???
Shankar
 
Mark Latham
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied and pasted the code you posted and tested it on Tomcat 4.1.29 with Mozilla Firebird 0.7 and IE 5.5 as the browsers. It worked as advertised with Firebird, but not with IE. With IE, it didn't display any output until the page was completely rendered.
Though I am always eager to disparage IE, I would not recommend depending on flushing the output of a slow servlet even if it worked correctly. I highly recommend refactoring such a servlet (or tweaking the business requirements) so it is more responsive. If, however, you need a quick and dirty browser-independent solution, you could always display an intermediate processing page while the code executes.
 
Mark Latham
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how it happened, but Shankar's followup question got deleted when I submitted my response. So the thread makes sense, I'll summarize his question regarding the quick and dirty method.
How can you do 2 responses for one request? As soon as you send back the 1st one, you'll lose your reference to the HttpServletResponse and won't be able to send anymore info back to the browser.

You submit to the intermediate page. The intermediate page has 2 purposes:
  • Let the user know her request is being processed
  • Forward the request on to the Servlet that will be doing the actual work


  • For example, I created a JSP named processing.jsp that contains the following:
    *Note: There's an extra n in the onnload because of Java Ranch JavaScript security restrictions.
    Then I request the page processing.jsp?target=flushServlet. The processing page is then immediately returned to the user (after it compiles the first time) while the Servlet is doing its work. This way the user gets immediate feedback that her request is being processed and she's discouraged from submitting the form again.
    And please remember, this solution is what I described as "quick and dirty". I still recommend making the Servlet itself respond faster.
    [ November 26, 2003: Message edited by: Mark Latham ]
    [ November 26, 2003: Message edited by: Mark Latham ]
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic