• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

The zip archive is corrupt after download in Java servlet  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i create servlet for create zip file of my database attachment and download,but result is a archive corrupt why? after open file this message recieve: C:\Users...\Downloads\DATA.zip: Unexpected end of archive

 
Bartender
Posts: 2078
276
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

abed asghari wrote:


What is fill_of_database?
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abed, one suggestion: You are doing two things there, creating a zip archive and sending it as a servlet response. Either of those two things could be the source of your problem, conceivably. So I suggest testing them separately. In particular create the zip archive and write it to a file locally, in plain old Java code and not in a servlet. If that works then try sending the archive as a servlet response.
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Paul, I checked  In particular create the zip archive and write it to a file locally is  correct but after download it will be corrupted
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod i checked zip file in server direction is correct but after download is corrupt
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote: Abed, one suggestion: You are doing two things there, creating a zip archive and sending it as a servlet response. Either of those two things could be the source of your problem, conceivably. So I suggest testing them separately. In particular create the zip archive and write it to a file locally, in plain old Java code and not in a servlet. If that works then try sending the archive as a servlet response.


thanks Paul, I checked  In particular create the zip archive and write it to a file locally is  correct but after download it will be corrupted
 
Master Rancher
Posts: 3677
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show your test code that successfully outputs to a local file?
Just so we can see whether there is some subtle difference.
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you show your test code that successfully outputs to a local file?
Just so we can see whether there is some subtle difference.



test for save in server from database that is correct

 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your servlet code you're calling "zos.finish()" and in your local download code you aren't. I doubt that's the subtle difference that Dave was hoping for, though.

Can I suggest that now you have done a local download which is okay and a remote download which is corrupt, that you bring the two together and compare them to see what's different?
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:In your servlet code you're calling "zos.finish()" and in your local download code you aren't. I doubt that's the subtle difference that Dave was hoping for, though.

Can I suggest that now you have done a local download which is okay and a remote download which is corrupt, that you bring the two together and compare them to see what's different?



i tested but not work ,
always in time unzip show message   :  "C:\Users\asghari\Downloads\MyZip.zip: Unexpected end of archive " and file in server directory is 60kB and after download is 56kB and if line below add to code

in time download show this alert :
                                                                                                                 

 
Dave Tolls
Master Rancher
Posts: 3677
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I was sort of hoping for something a bit more obvious...

One thing, though, can you give us the actual code for this line in your server code?
 
abed asghari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Yeah, I was sort of hoping for something a bit more obvious...

One thing, though, can you give us the actual code for this line in your server code?



i reply in

abed asghari wrote:Ron McLeod i checked zip file in server direction is correct but after download is corrupt

 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

abed asghari wrote:i tested but not work ,
always in time unzip show message   :  "C:\Users\asghari\Downloads\MyZip.zip: Unexpected end of archive " and file in server directory is 60kB and after download is 56kB...



Then I would change your servlet so that it writes the data to the response and also writes the same data to a file on the server. Then compare the two if there's still a problem.
 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


By the way, isn't closing the servlet's output stream a rather unusual thing to do? It's been a while since I wrote a servlet but I don't ever remember doing that.
 
Dave Tolls
Master Rancher
Posts: 3677
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen that sort of thing before, but not for a while.
It's not necessary (and neither is flushing).
All of that is handled by the normal servlet flow.

Unless something later on is attempting to put more stuff onto the output (which would result in an IllegalStateException I think) then closing the stream here should not have an adverse effect.
Of course, since it's not needed then it's probably worth taking it out.
After all, this servlet is not responsible for the stream, it is just using it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!