I have a servlet that sends a file to the browser.
I am sending these headers to the servlet.
if (request.isSecure()) {
response.addHeader("Pragma", "no-cache");
response.addHeader("Expires", "-1");
response.addHeader("Cache-Control", "no-cache");
} else {
response.addHeader("Cache-Control", "private");
response.addHeader("Pragma", "public");
}
if (isIE) {
response.addHeader("Content-Disposition", "attachment; filename=\"" + encName + "\"" );
response.addHeader("Connection", "close");
response.setContentType("application/force-download; name=\"" + encName + "\"" );
} else {
response.addHeader("Content-Disposition", "attachment; filename=\"" + encName + "\"" );
response.setContentType("application/octet-stream; name=\"" + encName + "\"" );
if (contentLen > 0) {
response.setContentLength(contentLen);
}
}
Then I send the file to the browser, but I have problems with the encoding of the file. The contents of the file are UTF-8, but I do not know how to send a header for this.
Does anyone have an idea how I can do this?
source
share