Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file download using servlet and showing progress

 
Vijaishanker bala
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

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.

Thanks

Vijai
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
http://simple.souther.us/not-so-simple.html
Look for LongRunningProcess.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To reduce page flickering you can use JavaScript with a timer for updating only status bar.
 
deepti dodda
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijjai,

Can you please post your solution to your problem in case you have!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic