Tôi có một servlet gửi tệp đến trình duyệt.Cách đặt mã hóa UTF-8 cho một tệp tải xuống servlet
Tôi gửi tiêu đề này trong 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);
}
}
Sau đó tôi gửi tệp đến trình duyệt nhưng tôi gặp sự cố với việc mã hóa tệp. Nội dung của tệp là UTF-8 nhưng tôi không biết cách gửi tiêu đề cho tệp này.
Có ai có ý tưởng như thế nào tôi có thể làm gì?
Tôi đang gặp sự cố với mã hóa sai khi tải xuống tệp html và thấy rằng sử dụng tiêu đề 'Accept: application/octet-stream' đã thực hiện thủ thuật. –