解決java web中safari瀏覽器下載後檔案中文亂碼問題
String fileName = "測試檔案.doc"; String userAgent = request.getHeader("User-Agent").toLowerCase(); //Java下載檔案時IE瀏覽器出現檔名亂碼 // 針對IE或者以IE為核心的瀏覽器: if (userAgent.contains("msie") || userAgent.contains("trident") ) { fileName = java.net.URLEncoder.encode(fileName, "UTF-8"); } else { // 非IE瀏覽器的處理: fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1"); } response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename=\"" + fileName + "\"");