首頁  >  文章  >  Java  >  java下載檔名亂碼解決方法詳解

java下載檔名亂碼解決方法詳解

尚
原創
2019-12-03 15:49:071954瀏覽

java下載檔名亂碼解決方法詳解

java下載檔案名稱亂碼的方法:(建議:java影片教學

每個瀏覽器的編碼都不一樣,火狐採用的是base64.ie和Google採用的是url編碼:

所以我們在設定回應頭的時候

Content-Type getServletContext().getMineType(filename);
Content-Disposition accachment;filename=编码后的filename

url編碼

name = URLEncoder.encode(filename, "UTF-8");

base64編碼

/**
传入文件的名称,进行Base64编码@param fileName@return
*/
public String base64EncodeFileName(String fileName) {
BASE64Encoder base64Encoder = new BASE64Encoder();
try {
return "=?UTF-8?B?"new String(base64Encoder.encode(fileName
.getBytes("UTF-8"))) + "?=";
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

更多java知識請關注java基礎教學欄位。

以上是java下載檔名亂碼解決方法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn