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

熱點內容
qit沒找到命令 瀏覽:62
exe安卓怎麼用 瀏覽:440
社保在哪裡查詢app 瀏覽:919
工程師和程序員有什麼不同 瀏覽:427
php正整數驗證 瀏覽:363
有個腹黑程序員男友是什麼體驗 瀏覽:110
pdf添加文本框 瀏覽:770
系統文件夾很大沒有文件 瀏覽:74
蘇寧電器app如何還分期 瀏覽:635
蘋果怎麼在主屏幕創建文件夾 瀏覽:627
河南雲伺服器租用虛擬主機 瀏覽:361
centos修改ip命令 瀏覽:779
租用伺服器屬於什麼服務類型 瀏覽:135
英雄聯盟說沒有網路連接到伺服器地址 瀏覽:28
單片機周期信號波形識別 瀏覽:42
演算法驅動的成長史 瀏覽:936
好又省APP怎麼用 瀏覽:576
pdf在線格式轉換jpg格式轉換器 瀏覽:868
中興捧月演算法大賽第二場 瀏覽:15
穿雲伺服器 瀏覽:394