导航:首页 > 编程语言 > 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相关的资料

热点内容
我的世界如何开mod服务器 浏览:904
人体写生pdf 浏览:317
android短信验证码倒计时 浏览:641
排课走班源码 浏览:222
程序员刚毕业去了小公司有发展吗 浏览:90
速腾怎么安装安卓手机互联 浏览:143
linux设备驱动程序代码 浏览:301
服务器的功耗怎么看 浏览:651
app组件哪里找 浏览:87
androidqq红包 浏览:412
服务器如何传输 浏览:456
如何快速将多个文件夹快速解压缩 浏览:114
程序员睡前都在想什么 浏览:37
少儿编程技能培训心得 浏览:458
白命令 浏览:816
headfirstjavapdf 浏览:552
广数980t怎么编程 浏览:592
无邪app在哪里下载 浏览:462
mac自带php目录 浏览:632
海淘小程序源码 浏览:750