Servlet下載文件時亂碼問題解決方法

String fileName =  "你的文件名";
response.setCharacterEncoding("UTF-8");
response.setContentType("APPLICATION/OCTET-STREAM"); 
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); 
if(isIE){
    // 若是是IE
    fileName = URLEncoder.encode(fileName, "ISO8859-1");
}
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setHeader("Content-Length", "你的文件長度");
bos = new BufferedOutputStream(response.getOutputStream());
相關文章
相關標籤/搜索