導航:首頁 > 編程語言 > 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哪個好 瀏覽:828
表格上加密碼 瀏覽:199
伺服器如何調時間 瀏覽:414
安卓怎麼跟蹤對方蘋果手機位置 瀏覽:829
pptp伺服器地址怎麼設置 瀏覽:940
藍月傳奇bt源碼 瀏覽:832
丹麥丹佛斯壓縮機 瀏覽:773
statapwcorr命令 瀏覽:135
怎樣看文件夾創建程序 瀏覽:641
文明重啟伺服器什麼時候重啟 瀏覽:981
app開發哪個比較好 瀏覽:977
程序員電腦卡了 瀏覽:831
壓縮空氣系統作用 瀏覽:404
三輪車用哪個app 瀏覽:29
手游游戲端源碼 瀏覽:92
沉井腳手架計演算法 瀏覽:921
加密twf文件怎麼列印 瀏覽:252
進入recoveryadb命令 瀏覽:3
伺服器為什麼不轉水冷 瀏覽:99
linux命令環境變數 瀏覽:488