aspose file tools*
The moose likes Servlets and the fly likes How to send the Zip file through the response Object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to send the Zip file through the response Object?" Watch "How to send the Zip file through the response Object?" New topic
Author

How to send the Zip file through the response Object?

sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 179
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

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

Joined: Apr 24, 2007
Posts: 179
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
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

So this is about Struts? Let me move it to the Struts forum then.
sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 179
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
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

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

Joined: Apr 24, 2007
Posts: 179
Thank you Paul. I will review my code.
sudha swami
Ranch Hand

Joined: Apr 24, 2007
Posts: 179
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

Joined: Apr 24, 2007
Posts: 179
Hi,

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




Thanks for your help and support


Sudha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to send the Zip file through the response Object?