spring文件下载乱码
来源:互联网 发布:什么是数据采集系统 编辑:程序博客网 时间:2024/04/29 14:34
Controller.java
@RequestMapping(value="/download")
public void downFile
(HttpServletRequest request,HttpServletResponse response) throws Exception{
String fileName=request.getParameter("fileName");
fileName = new String(fileName.getBytes("ISO8859-1"), "utf-8");
String realPath = request.getSession().getServletContext().getRealPath("/upload");
String filePath = realPath+File.separator+ fileName;
InputStream fis = null;
byte[] buffer = null;
try {
fis = new BufferedInputStream(new FileInputStream(filePath));
buffer = new byte[fis.available()];
fis.read(buffer);
}finally{
try {
if(fis !=null){
fis.close();
}
} catch (Exception e) {
}
}
response.setContentType("application/txt");
response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1"));
response.addHeader("Content-Length", "" + buffer.length);
OutputStream os = new BufferedOutputStream(response.getOutputStream());
os.write(buffer, 0, buffer.length);
os.flush();
os.close();
}
jsp:
对中文附件的编码:
function lookFile(){
var id = $("#lookFile").val();
$.ajax({
url:'${pageContext.request.contextPath}/credit/data/findAcrossById.action',
data:{id:id},
type:'post',
success:function(data){
var info = eval('('+data+')');
var fileName =info.fileName;
var filePath = info.filePath;
/*中文编码*/
window.location.href="${pageContext.request.contextPath}/credit/data/download.action?
fileName="+encodeURIComponent(fileName);
}
});
}
- spring文件下载乱码
- Spring MVC 文件下载过程中 出现下载文件乱码
- spring mvc 下载文件 IE浏览器文件名是乱码
- spring mvc 下载文件 IE浏览器文件名是乱码
- Spring MVC文件下载及中文文件名乱码解决
- Spring 实现 文件下载 (简洁,解决文件名乱码)
- java ibatis 读取mysql blob类型乱码 spring mvc文件下载csv文件乱码
- Spring MVC 实现文件下载,解决文件下载汉字乱码问题
- 下载文件乱码问题
- java文件下载乱码
- 文件下载中文乱码
- 文件下载乱码问题
- 使用spring mvc做文件下载时ie浏览器文件名乱码和下载不了问题解决
- 下载文件时,文件名乱码。
- Struts2 下载文件乱码问题
- 解决java下载文件乱码
- struts2文件下载,中文名称乱码
- 文件下载中文乱码问题
- 仲享登录界面html 采用table实现布局
- 从expandable中获取点击的子项
- UVa_136 - Ugly Numbers
- 大数据的利与弊
- CodeForces 2A - Winner(模拟)
- spring文件下载乱码
- POJ 1936 All in All
- 解决XCode无法生成Archive的问题
- jquery中$.ajax()的常用形式
- 一点点基础面试总结
- 错失英语,还是想错失另一个世界?
- Python初学者(零基础学习Python、Python入门)常见问题:书籍推荐、资料、社区
- 编译警告 warning: extra tokens at end of #undef 解决
- Java编程算法基础---有理数表示