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

熱點內容
易語言源碼轉python 瀏覽:364
程序員日祝福 瀏覽:883
阿里tv助手app哪裡下載 瀏覽:187
app活動怎麼關 瀏覽:202
java改變map 瀏覽:348
解壓鋼琴呂恆 瀏覽:991
程序員怎麼獲取被動收入 瀏覽:568
能不能別讓編程貓打電話給我了 瀏覽:687
量線突破指標源碼 瀏覽:458
雲伺服器阿里環境搭建 瀏覽:123
錐孔是怎麼編程的 瀏覽:133
加強箍和加密箍的區別 瀏覽:897
怎麼在騰訊伺服器上傳文件 瀏覽:643
公司門戶app安卓怎麼卸載 瀏覽:990
單片機中段源 瀏覽:143
電腦桌面文件加密要怎樣解除 瀏覽:963
quickfoxapp的商場在哪裡 瀏覽:2
單片機與pc機通信畢業設計 瀏覽:221
wan口的伺服器默認賬號是什麼 瀏覽:177
取小數位數php 瀏覽:716