У меня есть приложение, которое позволяет пользователям загружать некоторые файлы. Я запускаю его на VMware vFabric tc Server Developer Edition v2.9 (сервер по умолчанию в STS), и все в порядке. Но теперь мой сервер GlassFish, поэтому имя файла становится неправильным. Например - 30-60 от 19.01.2015.txtНеверное имя файла на разных серверах
Firefox: 30-60_ (без расширения)
Chrome: 30-60_ _19.01.2015.txt
Что неправильно? Код:
response.setHeader(
"Content-disposition",
"attachment;filename="
+ BufferUtil.getEncoded(distributionService.get(id)
.getTitle(), request) + ".txt");
response.setContentType("text/xml, text/plain");
BufferUtil.getEncoded:
public static String getEncoded(String text, HttpServletRequest request) {
String userAgent = request.getHeader("user-agent");
boolean isInternetExplorer = (userAgent.indexOf("MSIE") > -1);
text=text.replace(' ', '_');
try {
byte[] fileNameBytes = text
.getBytes((isInternetExplorer) ? ("windows-1250")
: ("utf-8"));
String dispositionFileName = "";
for (byte b : fileNameBytes) {
dispositionFileName += (char) (b & 0xff);
}
return dispositionFileName;
} catch (UnsupportedEncodingException ence) {
ence.printStackTrace();
return null;
}
}
содержит ли имя файла любые не-ASCII символов? – immibis
Да, это так ... – Tony