aspose file tools*
The moose likes Tomcat and the fly likes Download Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Download Files" Watch "Download Files" New topic
Author

Download Files

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
Where do I place a .csv file for the user to be able to download? I know I can create a servlet and change the MIME-TYPE of the output etc, but can't you just stick a file (filename.csv) in the directory /webapp-name/downloads/filename.csv and have the user go to the the URL for it?

For some reason it is giving me an error. Not a container error, but what looks like a browser error.

Thanks,
Jim
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
Maybe I didn't word that question very well. Is there a way to put an excel file on the server and allow the user to download it directly? Without creating a servlet which will read the file byte by byte, change the content-type of the response and set the bytes of the excel file into the response?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Some elaboration as to the nature of the error you are getting might be helpful.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
Here is the directory structure

webapp directory/downloadable_files/test.csv
webapp directory/downloadable_files/test.txt

The contents of these two files are the exact same. When I enter the URL for the .txt file (http://website.com/reports/downloadable_reports/test.txt) it renders in the browser without error.

When I enter the URL for the .csv file I get two popup boxes. The first one that is running in the foreground is like a javascript popup box only the heading at the top of the popup is "Microsoft Internet Explorer" and the message is "Internet explorer cannot download test.csv from website.com.

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

And there is a window in the background that is titled "File Download" but it is covered by the first window.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Turn off "friendly messages" in IE to see if you can gather more info on the nature of the error, and/or try it in another browser and see what happens there.
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
Friendly messages are turned off already, and when I turn them back on it doesn't really tell me anything much better. It first opens a warning window that I am about to download a file (test.csv) and asks if I want to open or save the file. When I click open or save it gives me the same error that it was giving when I had friendly messages turned off.

So basically what I am gathering is that with Tomcat you can't put a file in a directory and allow the user to download it directly. I find this behaviour strange since this is a pretty basic feature of IIS and you'd think it would be a pretty basic feature of Tomcat as well.

Am I wrong...?
Jim Babcock
Ranch Hand

Joined: Dec 03, 2004
Posts: 55
This is a standard functionallity in Tomcat, as well. It's just the error you're getting isn't providing much information... not a Tomcat issue .

Have you put a mime-type enter for csv files in web.xml? I have one for xls files that looks like this:



It could be Explorer is cramping because it doesn't recognize the mime-type

Jimbus
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
I've tried setting mime-types in web.xml and that doesn't work either. I also can't seem to access a microsoft word or powerpoint file that is on the server and both of their mime-types have entries in web.xml as well.

The wierd thing is that another guy on my team can access it just fine. It scares me to think that this is "just a problem with my browser" because more often than not there is more to it than that.

If nobody else can think of any solutions, I am going to try creating a servlet which will read the file byte by byte and write it to a byteArrayOutputStream and then set that into the response. This seems like horrible overkill though.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

So basically what I am gathering is that with Tomcat you can't put a file in a directory and allow the user to download it directly.


Nonsense. I've done it a bazillion times. The problem is clearly in your browser setup. Especially if, as you say, others can access the file without difficulty.

Have you tried alternate browsers as I suggested?
[ August 02, 2005: Message edited by: Bear Bibeault ]
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
No...because we have to support IE.
Jim Babcock
Ranch Hand

Joined: Dec 03, 2004
Posts: 55
I thinking browser issue. You could try installing firefox as a test. you could also try downloading something thats not associated a Microsoft product. Finally, use regedit to search for csv and see if you see anything funky.

I have had mime-type issue with Explorer in the past that didn't go away until I rebuilt the OS... but I'm not a windows guru.
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
We have tried several users browsers and everyone has the same problem. The strange thing is that if I request a file http://someurl.com/filename.csv and I am NOT logged in, I will first get prompted to enter password and then I am redirected to the requested URL where I can download the file (in other words it works). BUT...if I log into the site, then paste the URL directly into that browser session to which I am logged in it will not download the file and gives me the errors suggested above.

Any ideas?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download Files