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.
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.
Joined: May 27, 2003
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com