Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

probelom while usuing content-disposition in response.setHeader()

 
vasu devan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

i am occuring probelom while downloading file through servlets following are the steps i have done...
Step 1)get the filename
Step 2)Set the header as content-disposition
Step 3)after this save dialog opened and the control is given to saving the file

my question is how can i track the download?
ie..,Tracking Download, like completion of download

following is code that i have used

if((sContentType != null))
{
response.setContentType( sContentType );
response.setHeader("content-disposition","attachment; filename="+sFileName);
try{
while( (iTemp = dis.read( bData ) ) != -1 )
{
out.write( bData , 0 , iTemp );
out.flush();
}
}catch(Exception e)
{
System.out.println("Exception :- " + e);
}
}

while performing the operations file downloading ,it takes control and after downloading operations i redirected to new JSP page...
but ITS not GOING to next page...

provide me the solutions
or is any alternative solutions is there

Note:
MIME Type is set in web server

Thanks in advance

cheers
vasu
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while performing the operations file downloading ,it takes control and after downloading operations i redirected to new JSP page...
but ITS not GOING to next page...

You can't do this. The client sends a request, you send a response and you only get to send one response. To do your trick you'd either have to send two responses ie download this and go here, or you would have to get the client to send two requests.

There are ways to do it the second way, but you can't track the download on the client side so that the reload happens after the download completes. You could do something more complicated like this, but I really don't think it's worth it:
Client requests a page.
You send a page that has javascript to start the download and then reload a second page.
This second page continues to refresh periodically, or you could make it hang but that's usually a very bad idea. More on this second page in a sec.
You track the bytes downloaded by the client so that you can tell when they've got it all. Set a value somewhere.
Now the second page notices the download is complete. You send the real page and stop reloading the second page.

This all sounds like too much work for no real purpose, but that's just my opinion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic