下载excel文件名字乱码问题处理
来源:互联网 发布:我的手机淘宝怎么打不开 编辑:程序博客网 时间:2024/05/13 17:26
package com.dreamwin.cclib.naga.view;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.dreamwin.statis.StartUp;/** * 输出文件视图 * * * @author niuxx * */public class FILEView extends BaseView implements View { /** 需要输出的文件路径 */ private String filePath; /** * 带模板路径的构造器 * * @param templateName * 模板路径 */ public FILEView(String filePath) { this.filePath = filePath; } public void render(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.render(request, response); // response.setCharacterEncoding("UTF-8"); String cStr1 = filePath; // cStr1 = URLDecoder.decode(filePath,"UTF-8"); String view_name = filePath.substring(filePath.lastIndexOf("/") + 1); String cFilePath; cFilePath = StartUp.deployDirectory + cStr1; File file = new File(cFilePath); if (!file.exists()) { return; } File downFile = new File(cFilePath); response.setContentType("binary/octet-stream;charset=UTF-8"); // response.setContentType("application/x-msdownload"); // 判断浏览器版本,设置相应编码格式 String userAgent = request.getHeader("User-Agent"); System.out.println(userAgent); userAgent = userAgent.toLowerCase(); if (userAgent.indexOf("msie") != -1) { //response.setHeader("Content-Disposition", "attachment; filename=\"" // + URLEncoder.encode(view_name, "UTF-8") +"\""); response.setHeader( "Content-Disposition", "attachment;filename=" + new String(view_name.getBytes("gb2312"), "ISO8859-1" )); } else { String fileName = new String(view_name.getBytes("UTF-8"), "ISO8859-1"); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); } ServletOutputStream out = response.getOutputStream(); InputStream is = new FileInputStream(downFile); byte[] bytes = new byte[1024]; while (true) { int chunk = is.read(bytes); if (chunk == -1) { break; } out.write(bytes, 0, chunk); } is.close(); is = null; out.flush(); out.close(); } public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; }}
0 0
- 下载excel文件名字乱码问题处理
- 下载excel文件名字乱码问题处理
- 文件下载文件名乱码问题处理
- EXCEL下载乱码问题
- MVC下载Excel文件:js接受乱码 简单处理办法
- 解决Tomcat下载中文名字文件乱码
- servlet 下载文件名字 中文乱码 解决
- 下载文件名字乱码问题,json_encode解决Ajax 返回字符串数据不显示问题
- 下载文件乱码问题
- 文件下载乱码问题
- Python处理MLDonkey 下载中文文件乱码问题
- Python处理MLDonkey 下载中文文件乱码问题 (2)
- 上传下载文件(并处理了下载文件名乱码问题)
- HTTP 文件下载时中文文件名乱码问题处理
- php 下载名字乱码
- 文件下载文件名乱码处理
- 不同浏览器下载文件 中文名字乱码解决
- servlet使用迅雷下载excel文件乱码
- mysql error (ERROR大全)
- android下载的断点续传的功能的实现
- Qt动态库引用动态库,编译提示:无法打开包括文件
- cron表达式详解
- MariaDB主从配置
- 下载excel文件名字乱码问题处理
- 8大排序之 ---------归并排序 与时间复杂度
- 深入剖析Java中的装箱和拆箱
- 关于解决placeholder 颜色问题
- Java中导入、导出Excel
- PhpStorm的常用快捷键
- C语言学习-分支结构 (简单明了)
- layer弹窗iframe页面,关闭弹窗方法导致form表单无法提交到服务器
- overflow滚动条样式调整