A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Sending file with Servlet, Problem if filename contains whitespaces
Joined: Oct 25, 2004
Jan 30, 2006 02:23:00
I'm sending files by a
. I'm setting the filename by using
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
This works fine. But if the filename contains whitespaces, my Firefox cuts the filename before the whitespace. So all chars behind the whitespace (including the extension!) get lost. Are there any solutions for this?
Joined: Nov 24, 2005
Jan 30, 2006 02:26:00
Did you try with double-quotations too ?
All roads lead to JavaRanch
Joined: Dec 11, 2004
Jan 30, 2006 04:00:00
What I would try is this:
Create an empty directory on your webserver (call it junk).
Put a file with spaces in the name ("space in name.html")
Point your browser at that directory.
Click on the link for that file.
Using the LiveHTTPHeaders plugin for FireFox, view the filename as it's being sent.
This will be the default way of packaging files with spaces in the name over HTTP.
I did this and saw:
[B]GET /junk/space%20in%20name.html HTTP/1.1[/B] Host: <a href="http://www.souther.us" target="_blank" rel="nofollow">www.souther.us</a> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5
This shows me that servers handle spaces in th names by URL Encoding them and that browsers expect this and already know how to deal with it.
[ January 30, 2006: Message edited by: Ben Souther ]
How to ask a question...
Simple Servlet Examples
Joined: May 29, 2002
Jan 31, 2006 11:51:00
res.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
I agree. Here's the link:
subject: Sending file with Servlet, Problem if filename contains whitespaces
JavaMail: File extension omitted by invoking part.getFileName
c:out trim problem
How to ignore whitespace in text nodes?
trim-directive-whitespaces - Seriously has anyone gotten this to work?
String --> split/regex question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014