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

熱點內容
宏定義編譯後不變 瀏覽:397
如何搞免費伺服器 瀏覽:206
神經系統pdf 瀏覽:665
如何查看伺服器上的資料庫伺服器 瀏覽:188
壓縮機型號v代表什麼 瀏覽:50
旅遊類源碼 瀏覽:860
電腦伺服器類型怎麼設置 瀏覽:228
pdf炒股 瀏覽:784
伺服器地址缺少埠號什麼意思 瀏覽:530
下載需要解壓的小說用哪個軟體 瀏覽:534
廣東分布式伺服器雲主機 瀏覽:583
伺服器忙打不開怎麼辦 瀏覽:15
tif壓縮軟體 瀏覽:413
程序員那麼可愛陸漓上班第1天 瀏覽:952
macbookair自帶什麼app 瀏覽:701
如何關了加密的軟體 瀏覽:581
程序員p2p待遇 瀏覽:922
ipd編譯要求 瀏覽:936
壓縮解壓王怎麼用 瀏覽:34
伺服器共享文件如何備份 瀏覽:758