aspose file tools*
The moose likes Struts and the fly likes How to download different files in struits dppending on the file format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to download different files in struits dppending on the file format" Watch "How to download different files in struits dppending on the file format" New topic
Author

How to download different files in struits dppending on the file format

Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 84
I am having two choices in my jsp which allows me to choose a CSV or a PDF to download. I have the files in the respective format on the disk.
I want to put only the required format in the content type so that i can recognize the file while downloading.

If i give response.setContentType("application/pdf");
it works fine for the pdf
but if i set the response.setContentType("application/csv");
it doesn't identify it as a csv file.

WHERE DOES THE PROBLEM LIE?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Here is a link to a listing of registered MIME types: http://www.iana.org/assignments/media-types/

I do not see an "application/csv" but there is a "text/csv" listed. Do you expect the CSV document to open in a spreadsheet program (like Excel)? I don't know if using "text/csv" will do the trick or not.

- Brent
Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 84
IE doesn't recognise how to open the file when i give it a text/csv format.
It simply prompts for a save dialog instead of the usual OPEN/SAVE dialog.
Does this has something to do with the IE plugin for excel or CSV.
Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 84
it worked if i give a "application/vnd.ms-excel" type.
But i have same problem of not getting the OPEN button on the open save dialog with the "zip" file format.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This is related to the settings you have made for file extensions within Microsoft Windows. If you go into Windows Explorer and define Excel as the porgram to be used for a file extension of .csv, IE will give you the option of opening the file with Excel when you download it.


Merrill
Consultant, Sima Solutions
Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 84
I think i did not write the question right.
I am getting the able to open the CSV file properly. My problem is that if i give Content-type as application/zip for a zip file to be downloaded then it is not recognized by IE or mozilla. it just gives me a save dialog instead of the normal open/save dialog.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The same principle applies. Unless you have told Windows that you want a file with extension .zip to be opened with a specific program, IE doesn't know how to open it, so the only option it will give you is to save it.

You might try application/x-zip-compressed instead. If you're using IE, This link contains some good information on how it all works.
[ January 01, 2007: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to download different files in struits dppending on the file format