jsp下载文件名乱码
我用流下载文件,下面是部分代码,在弹出的下载框中的文件名是乱码,如果加了URLEncoder.encode(filedisplay,"UTF-8");就会变成%E7%BB...
我用流下载文件,下面是部分代码,在弹出的下载框中的文件名是乱码,如果加了URLEncoder.encode(filedisplay,"UTF-8");就会变成%E7%BB%99%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E7%9A%84%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E5%90%8D这种形式。
response.reset();
response.setContentType("application/x-download");
String filedisplay = "给用户提供的下载文件名";
filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
哪位知道怎么弄啊,上网找了好多资料都不行 展开
response.reset();
response.setContentType("application/x-download");
String filedisplay = "给用户提供的下载文件名";
filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
哪位知道怎么弄啊,上网找了好多资料都不行 展开
1个回答
展开全部
摘我项目中下载文件的代码,希望对你有帮助
File downFile=new File(path,fileName);
response.setContentType("binary/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(downFile.getName().getBytes("gb2312"),"iso8859-1"));
ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream is=new FileInputStream(downFile);
byte[] bytes = new byte[1024];
while (true) {
int chunk = is.read(bytes);
if (chunk == -1) {
break;
}
servletOutputStream.write(bytes, 0, chunk);
}
is.close();
is = null;
File downFile=new File(path,fileName);
response.setContentType("binary/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(downFile.getName().getBytes("gb2312"),"iso8859-1"));
ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream is=new FileInputStream(downFile);
byte[] bytes = new byte[1024];
while (true) {
int chunk = is.read(bytes);
if (chunk == -1) {
break;
}
servletOutputStream.write(bytes, 0, chunk);
}
is.close();
is = null;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询