Issue
I´m trying to serve binary response in my java servlet. First, I get the requested data from database and than try to set it as a response like this:
ResultSet rset = (ResultSet) stmt.executeQuery();
if (rset.next())
{
byte[] bData = rset.getBytes("Soubor");
String sJmenoSouboru = rset.getString("Jmeno_souboru");
response.setHeader("Content-Disposition","attachment;filename=" + sJmenoSouboru);
//response.setHeader("Content-Description", sJmenoSouboru);
response.setHeader("Content-Transfer-Encoding", "binary");
//response.setContentType("application/pdf");
response.setContentType("application/octet-stream");
ServletOutputStream hOutStream = response.getOutputStream();
hOutStream.write(bData);
hOutStream.flush();
hOutStream.close();
}
This works fine, until there is a '§' character in file name. Than i get ERR_SPDY_PROTOCOL_ERROR. Mentioned character should be usable in file names as far as I know. Does anybody know, where could be the problem?
Solution
As stdunbar mentioned in comments, the problem is that '§' is a non-ASCII character, that needs to be escaped in file name. I solved it by changing this line of code:
String sJmenoSouboru = URLEncoder.encode(rset.getString("Jmeno_souboru"), StandardCharsets.UTF_8.toString());
Answered By - Mono