火狐下poi導出文件名稱亂碼問題

代碼如下:

// 導出 excel 文件

File file = new File(targetPath);
FileInputStream fis = new FileInputStream(excelFile);
response.setContentType("application/octet-stream");
String userAgent = request.getHeader("User-Agent");  
       byte[] bytes = userAgent.contains("MSIE") ? file.getName().getBytes() : file.getName().getBytes("UTF-8"); // name.getBytes("UTF-8")處理safari的亂碼問題  
       String name = new String(bytes, "ISO-8859-1"); // 各瀏覽器基本都支持ISO編碼 
response.setHeader("Content-Disposition", "attachment;filename=\"" + name + "\"");
//response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
//response.setHeader("Content-Length", String.valueOf(file.length()));

FileCopyUtils.copy(fis, response.getOutputStream());


參考文檔:http://f0rb.iteye.com/blog/1308579

發佈了26 篇原創文章 · 獲贊 7 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章