Python 官方文档:入门教程 => 点击学习
目录文件流输出文件名中文不显示使用如下方法没有解决解决方法response下载时中文文件名乱码文件流输出文件名中文不显示 response返回文件流 用response.setHea
response返回文件流 用response.setHeader(“Content-disposition”, “attachment; filename=”+fileName);结果中文名称以“—”下滑下显示。
response.setCharacterEncoding(“UTF-8”);
response.setContentType(“text/html;charset=UTF-8”);
response.setLocale(new java.util.Locale(“zh”,“CN”));
原因是这些操作是针对返回内容进行编码设置,而我这里文件名称设置于header;
将文件名称转换为ASCII码~
如下:
// 一万行代码没有显示
OutputStream output = null;
try {
response.reset();
response.setContentType("application/msexcel;charset=UTF-8");
// response.setCharacterEncoding("UTF-8");
fileName = URLEncoder.encode(fileName,"UTF-8");
output = response.getOutputStream();
response.setHeader("Content-disposition", "attachment; filename="+fileName);
wb.write(output);
if(output != null) output.close();
} catch (IOException e) {
// TODO
e.printStackTrace();
}
FileInfo info = new FileInfo(strFilePath);
long fileSize = info.Length;
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Accept-Language", "zh-cn");
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode(info.Name));
//不指明Content-Length用Flush的话不会显示下载进度
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(strFilePath, 0, fileSize);
Response.Flush();
Response.Close();
info.Delete();
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: response文件流输出文件名中文不显示的解决
本文链接: https://www.lsjlt.com/news/164132.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0