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

熱點內容
哪個領域演算法好 瀏覽:380
用命令行編譯java 瀏覽:677
筆趣閣app哪個是正版手機app 瀏覽:427
程序員這個工作好嗎 瀏覽:898
agps定位伺服器地址 瀏覽:659
用水做的解壓玩具怎麼做 瀏覽:418
安卓411能下載什麼 瀏覽:304
小海龜logo命令 瀏覽:493
java製作界面 瀏覽:895
台達plc編程電纜製作 瀏覽:249
30多歲當程序員 瀏覽:442
怎樣把表格轉換成pdf 瀏覽:514
行列式分解演算法 瀏覽:291
mscoreedll是什麼文件夾修復 瀏覽:697
什麼app測臉型 瀏覽:43
cf手游刀戰演算法 瀏覽:318
北京壓縮米飯 瀏覽:554
施工員與程序員哪個好 瀏覽:207
vc與word編程 瀏覽:951
androidmenu文字顏色 瀏覽:983