Is this possible?

H

Harry

Firstly sorry for cross posting but not really sure which group this belongs
in?

Anyway, I have a webapp that basically consists of 2 screens, search critera
& results

I want to be able to provide a way for the user to download a zipped up
excel file of the results.

I can quite easily create a excel file using POI & zip it up using
java.util.zip which creates a zip file on the server. Then add a link to
this file on the results page which when clicked will produce the standard
download dialog box & alls well.

The problem is I have to create the zip file every time the results
generated & displayed but some users might not want this faclity!

Is it possible to have a button/link etc... that when clicked create's the
zip file & produces the download dialog box WITHOUT changing the results
page?

Any ideas?

thanks

harry
 
A

Andy Fish

yes

simply have the download URL pointing to a servlet (or whatever server side
technology you are using)

in the servlet build the zip file, set the content-type to
application/x-zip-compressed and write out the zip data as the HTTP body.

note that you with java.util.zip, you can simply open up a zipOutputStream
on the response's output stream so you don't need to save it to a file at
all.

I would also suggest the url ends in .zip as well. Sometimes IE seems to
look at the file extension of the URL as well as the content type

Andy
 
M

Michael Borgwardt

Harry said:
I can quite easily create a excel file using POI & zip it up using
java.util.zip which creates a zip file on the server. Then add a link to
this file on the results page which when clicked will produce the standard
download dialog box & alls well.

The problem is I have to create the zip file every time the results
generated & displayed but some users might not want this faclity!

Is it possible to have a button/link etc... that when clicked create's the
zip file & produces the download dialog box WITHOUT changing the results
page?

Sure, simply link to a servlet that returns the data directly as its output.
There's no need to create a file on the server at all.
 
H

Harry

wow, thanks for that chaps, seems to work perfectly - without having store
files on the server aswell!!!!!!!!!1

Just got to work out now how to specify filename of excel file being
saved? - don't suppose you know this one? - comes out currently like
"exportservletdad585c4.xls" with exportservlet obviously being the name of
my servlet!

thanks

harry
 
M

Michael Borgwardt

Harry said:
wow, thanks for that chaps, seems to work perfectly - without having store
files on the server aswell!!!!!!!!!1

Just got to work out now how to specify filename of excel file being
saved? - don't suppose you know this one? - comes out currently like
"exportservletdad585c4.xls" with exportservlet obviously being the name of
my servlet!

You can specify a file name in the HTTP header Content-disposition:
 
A

Andy Fish

I have had trouble with content-disposition headers in the past. if that
still doesn't work reliably, you might find that making sure the URL ends in
/<filename>.xls will help, certainly for IE
 
G

Guest

I would also suggest the url ends in .zip as well. Sometimes IE seems to
look at the file extension of the URL as well as the content type

Use the Content-Disposition HTTP header:

Content-Disposition: attachment; filename=file.zip

On a project I'm working on, we have to generate tons of PDF reports. To
fool IE, we mapped all URLs ending in ".pdf" to a package understood by
our servlet.

For example, "/reports/exceptions.pdf" gets translated into class
"com.wingetsolutions.reports.pdf.exceptions" which implements a
PDFGenerator interface. Of course the servlet only checks for this class
if a static pdf file doesn't already exist in the proper place on the
server.

Just my 2 cents,
La'ie Techie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top