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

热点内容
时钟置换算法指针变化规则 浏览:245
微信加密能否改密码 浏览:104
android权限组 浏览:169
2017单片机 浏览:476
让孩子感兴趣编程的电影 浏览:259
用颜料制作脆皮解压球 浏览:932
火箭解压器 浏览:72
cnet中级程序员面试题 浏览:190
单片机怎么做人脸识别 浏览:154
监狱办理工商银行app怎么办呢 浏览:819
c语言写编程时需要用什么输入法 浏览:590
生发程序员 浏览:167
高考英语pdf 浏览:418
哈利波特忘记服务器怎么办 浏览:824
怎么看其他电脑共享文件夹 浏览:513
py文件夹后缀 浏览:723
你对我们的app有什么建议 浏览:584
phpgetcookie 浏览:145
程序员最烦遇到的单词 浏览:125
开始服务器升级需要什么 浏览:985