aspose file tools*
The moose likes JSF and the fly likes how to download a zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to download a zip file" Watch "how to download a zip file" New topic
Author

how to download a zip file

Jordan Smith
Ranch Hand

Joined: Apr 06, 2008
Posts: 89
Hi!

I would like to download a zip file from a constant location on the server to the user (with a dialog).

I wrote the following code but it doesn't display it:

How can i open a save dialog? is there a util for that?
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Try changing the response content type to "application/zip" and also response transfer encoding to binary... it should prompt you with the save/open dialog.
Vinay Kaparthi
Greenhorn

Joined: Jul 29, 2011
Posts: 1
Try using context.responseComplete(); after out.close();
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62

It's been a long time now, but it does not hurt asking...

Have this be resolved?

I'm with a similar problem, the SaveAs dialog box is not displayed in the browser, and I'm already using

context.responseComplete();

in my code.

Jordan, if you're still around and remember how to solve this, I'd be glad to have your thoughts.

I've been working on this and counting on this thread to share what's happening here: http://www.coderanch.com/t/555081/JSF/java/response-setContentType-application-download-not#2518376

Thanks in advance!


DJ aspirant, Engineering undergraduate, Tokusatsus addicted, fond of English language and Asia's, Buddhist, blogger, etc. I'll need to insert all these attributes in a Java class and manage to create methods for handling my overwhelming life
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

Don't use JSF to generate non-HTML content.

JSF is not an all-or-nothing architecture. A JSF app can also contain servlets, traditional JSPs, and even Struts code.

The power of JSF is that allows you to manage HTML content (especially form content) easily. It does that by assuming total control over the HttpResponse and its output stream, however, and you inject your own low-level efforts at your peril.

It's a lot safer, cleaner, and simpler to provide the ZIP download from a servlet that to try and force JSF to do it.

There's a related thread on this forum where I've discussed similar issues.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ajeeth Kumar
Ranch Hand

Joined: Mar 30, 2005
Posts: 56
Marcos Silvestri wrote:It's been a long time now, but it does not hurt asking...

Have this be resolved?

Jordan, if you're still around and remember how to solve this, I'd be glad to have your thoughts.

I've been working on this and counting on this thread to share what's happening here: http://www.coderanch.com/t/555081/JSF/java/response-setContentType-application-download-not#2518376

Thanks in advance!


Are you still facing issues or is it resolved?

The best solution that worked for me is to stop adding the response content behaviour manipulations in JSF.
Try adding response.complete and just do a flush before closing the streams. No need to use ZipOutput streams. Use buffer streams only if you are planning on sending huge data(more than 2 MB/4 MB approx)
Marcos Silvestri
Ranch Hand

Joined: Dec 06, 2009
Posts: 62


Thanks for the answer Ajeeth, but I'm no longer dealing with that.

Thanks anyway
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to download a zip file
 
Similar Threads
UnZipping Occurs in Server System only
URL download
JSF: Save session context to local file
Redirect after close download box
What's the best way to download files from a web app?