• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Getting Different sizes at different times of downloading of file using servlets.

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using below code to download file using servlets.But when i am downloading file for first time it is showing exact file size,from second time it is showing multiple of 2 to the previous size of file.I want to get file size as same for every time of downloading.Can any one please help me to do that.


Here filePath is the path of the file which i want to download.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this was my problem I would start by:

1. Get the File size, log it, and use setContentLength() to set the Content-Length header in the response.
2. log all of those exceptions.

Bill
 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi william,
I have tried setting content-length.If i set the content length i am getting only 1kb data of file instead of whole zip file.when i am trying to open that zip it is showing that the zip got corrupted.can anyone please help me how to resolve this..

Thanks in advance.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I call your attention to item 2. log all the exceptions

There is no way that setting Content-Length to the correct file size is going to truncate your download at 1K.

Bill
 
SaiManasa Dasari
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi william,
I have logged all the eceptions.I did not get any exception.Its downloading fine.But when downloading,file size is getting multiple of 2 of before downloading file size.
I am using following code to set content-length.

Can anyone please help me to resolve this.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Logically, if the servlet is sending the correct content, the fault must lie on the client side. Doubling the size sounds like the client side is appending to the existing file.

If this was my problem I would examine a doubled file with a programmer's editor capable of displaying hex, particularly at the point where the file is supposed to end.

What is this supposed to do:



Bill
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you need to use below code in your servlet for caching not to happen with response.

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic