• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download Files

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some elaboration as to the nature of the error you are getting might be helpful.
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...?
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No...because we have to support IE.
 
Jim Babcock
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic