一開始設置的Content-type爲:
response.addHeader("Content-type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.addHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
結果在手機瀏覽器下載docx文檔時,能出現下載任務,但是下載總是失敗。
後來嘗試將Content-type改爲如下形式:
response.addHeader("Content-type", "application/x-msdownload");
response.addHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
改完之後就可以成功下載word文檔了。