導航:首頁 > 編程語言 > java下載response

java下載response

發布時間:2024-12-18 08:57:58

java文件下載不顯示中文文件名,

//下載
response.setContentType("application/x-msdownload");
String filename = "測試.zip";
String iso_filename = SysParameter.parseGBK(filename);
response.setHeader("Content-Disposition",
"attachment;filename=" + iso_filename);

ServletOutputStream op = response.getOutputStream();
op.write(ab);
op.flush();
op.close();

SysParameter.parseGBK 方法:
// 將GBK字元轉化為ISO碼
public static String parseGBK(String sIn) {
if (sIn == null || sIn.equals(""))
return sIn;
try {
return new String(sIn.getBytes("GBK"), "ISO-8859-1");
} catch (UnsupportedEncodingException usex) {
return sIn;
}
}

② java如何實現下載彈出的對話框

Java實現點擊下載文件的時候,彈出「另存為」對話框,選擇保存位置,然後下載,代碼如下:

publicvoiddownLoad(StringfilePath,HttpServletResponseresponse)
throwsException{
System.out.println("filePath"+filePath);
Filef=newFile(filePath);
if(!f.exists()){
response.sendError(404,"Filenotfound!");
return;
}
BufferedInputStreambr=newBufferedInputStream(newFileInputStream(f));
byte[]buf=newbyte[1024];
intlen=0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition","attachment;filename="+f.getName());
OutputStreamout=response.getOutputStream();
while((len=br.read(buf))>0)out.write(buf,0,len);
br.close();
out.close();
}
閱讀全文

與java下載response相關的資料

熱點內容
程序員考核d 瀏覽:237
自助游中國pdf 瀏覽:738
安卓p40是什麼手機 瀏覽:79
24cxx編程器 瀏覽:583
陰陽師如何查看哪個伺服器有ID 瀏覽:308
公務員照片壓縮 瀏覽:450
編譯的時候怎麼找未定義的函數 瀏覽:344
有什麼我的世界伺服器 瀏覽:298
伺服器亮綠燈是什麼意思 瀏覽:629
python畫的圖如何保存高清版 瀏覽:491
10的搭接還用加密嗎 瀏覽:365
bytedance這個文件夾是什麼意思呢 瀏覽:588
演算法站的客體 瀏覽:76
src文件夾c語言怎麼運行 瀏覽:23
怎麼把已安裝的app放到桌面 瀏覽:946
如何查看蘋果手機app是否取消訂閱 瀏覽:772
u盤加密之後手機可以打開嗎 瀏覽:46
單片機串口發射怎麼回事 瀏覽:479
程序員假裝自己很忙 瀏覽:800
程序員能力關鍵詞 瀏覽:617