導航:首頁 > 編程語言 > 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相關的資料

熱點內容
如何app搭建伺服器 瀏覽:844
javastringblob 瀏覽:295
王瑤pdf 瀏覽:857
開掛軟體顯示請連接伺服器地址 瀏覽:916
蘋果怎麼下載安卓倩女 瀏覽:584
vip藍光視頻解析網站源碼 瀏覽:940
伺服器ps1ps2是什麼意思 瀏覽:858
seo命令 瀏覽:866
可代理雲伺服器 瀏覽:973
本地伺服器連接失敗是什麼意思 瀏覽:866
華為平板如何將應用app分身 瀏覽:897
微信顯示無法連接到伺服器1302什麼意思 瀏覽:625
java有哪些函數 瀏覽:752
隨遇app怎麼收費 瀏覽:203
如何將家用電腦做伺服器外網 瀏覽:805
命令方塊如何設置有條件 瀏覽:585
基於雲伺服器的井下監控裝置 瀏覽:786
程序員頸椎變形 瀏覽:656
android登陸伺服器 瀏覽:426
我的世界為什麼顯示無法連接至伺服器 瀏覽:981