• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to send the Zip file through the response Object?

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Hi,

I have a zip file on the file system. When the user clicks download, the zip file needs to downloaded. I am getting the error" Internet Explorer cannot download the file.

This is my code:




Can you please help me out.

Thanks
Sudha
 
Sheriff
Posts: 28372
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would expect that the code is not finding a file in that "tmp" directory and is going directly to the catch block. So check wherever stderr is redirected to in your servlet container and you should find the stack trace there.

It's a bad idea to use relative paths in a JEE environment, because you don't know what the servlet container's current working directory is. And if you do know, you still can't rely on that knowledge. And if you assumed the path was going to be relative to your web application in some way, well, it isn't.
 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Thank you for your reply.

It is able to read the file. It is not going to catch. I am the seeing the following in the log file
getOutputStream() has already been called for this response . Instead of using Servlet, I am using Struts Action class.

Thanks
Sudha

 
Paul Clapham
Sheriff
Posts: 28372
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So this is about Struts? Let me move it to the Struts forum then.
 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Can you please move this discussion forum back to Servlet? Because, I changed my code, I am using Servlets now. I am able to download the zip file. When I extract the zip, but I am seeing following error:

When testing/extracting WinZip was unable to read file #-1 in the Zip file
Possible cause: file transfer error



Thanks
Sudha

 
Paul Clapham
Sheriff
Posts: 28372
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, I will move it back.

Your error means that you didn't copy all the data correctly from the file to the servlet's output stream, and therefore the data received at the client is not a well-formed ZIP archive.
 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Paul. I will review my code.
 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tested the code above. Instead of sending the zip file as the response object via ServletOutputStream, I am writing the zip file on the file system. When I extract the zip file on the harddisk, I don't see any problem.



Instead of ServletOutputStream, can I send the byte[] in any other outputstream in response object

Any help is appreciated.

Thanks
Sudha
 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Finally it started working. I had to set this in the response object




Thanks for your help and support


Sudha
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic