-1

I have GWT app from where I can download some files. And I've got a problem with encoding.

Here is some code:

String n = "Żółw testuje ąśżźć !#$%~ du";
String tmp = new String();
for(int i = 0; i < n.length(); i++) {
    String t = Character.toString(n.charAt(i));
    if(" =-_]}[{)(&^%$#@!~`,".contains(t))
        tmp +=t;
    else
        tmp += URLEncoder.encode(t, "UTF-8");
}

response.setHeader("Content-Disposition", "attachment; filename=\"" + tmp +"\"");
System.out.println(tmp);

In Chrome and IE the filename is "Żółw testuje ąśżźć !#$%~ du" but in Firefox is "%C5%BB%C3%B3%C5%82w testuje %C4%85%C5%9B%C5%BC%C5%BA%C4%87 !#$%~ du". I already tested with Windows-1252, ISO-8859-1, Cp852 and with "attachment; filename*=utf-8''" but no good.

Any suggestions?

  • WHy the downvote? Seems like a perfectly legitimate question to me – fge Jun 16 '13 at 12:40
  • See [here](http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http), but the post is 3 years old, I don't know how the situation has evolved since then – fge Jun 16 '13 at 12:42
  • Thx fge, sporaks answer was very helpful. – user2490669 Jun 16 '13 at 21:14

1 Answers1

0

See the relevant spec -- http://greenbytes.de/tech/webdav/rfc6266.html -- and the test cases at http://greenbytes.de/tech/tc2231/.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98