This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes file download using servlet and showing progress Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "file download using servlet and showing progress" Watch "file download using servlet and showing progress" New topic

file download using servlet and showing progress

Vijaishanker bala
Ranch Hand

Joined: Sep 08, 2005
Posts: 82

In my web application, I need to provide functionality to enable downloading of a file from the server using a servlet. After having provided that functionality by means of the following code,

I now need to display progress/status as to whats happening on the server side. The file being downloaded is a result of a few operations like generating pdfs and merging them. This takes quite some time and until then the client is left in the dark and all he can does is stare at a blank browser window. So as to enrich user experience I wanted to show progress of the files being merged and also the size of the end file that has been downloaded before it finally opens on the browser window, Is this possible and is there any particular pattern to follow.



When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." <br />Linus Torvalds
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

I do this by kicking off the long running process in a new thread and then immediately returning the user to a status page.
The status page refreshes itself (using a META tag) every n seconds to check with server. If the job is not done, I return the status page. Once it's finished, I stream the file or forward to a page with a link to the file.

If you're interested, I have a small demo app that does this.
Look for LongRunningProcess.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

To reduce page flickering you can use JavaScript with a timer for updating only status bar.

Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
deepti dodda

Joined: Mar 13, 2013
Posts: 1

Can you please post your solution to your problem in case you have!
I agree. Here's the link:
subject: file download using servlet and showing progress
It's not a secret anymore!