Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending file with Servlet, Problem if filename contains whitespaces

 
Mark Mescher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm sending files by a Servlet. 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?

Thx
Mark
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try with double-quotations too ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

    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 ]
     
    Michael Remijan
    Author
    Ranch Hand
    Posts: 130
    7
    Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic