姚博文 下载:javax.servlet.ServletException: ClientAbortException: java.net.SocketException: Broken pipe
来源:互联网 发布:js里的this中文意思 编辑:程序博客网 时间:2024/06/08 08:36
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession session = HttpRequester.getHttpSession();
Object su = session.getAttribute("ACCOUNT");
if (su == null) {
System.out.println("session超时");
throw new Exception("session超时");
}
taskResultExcel = downloadFile.substring(downloadFile.lastIndexOf("/")+1, downloadFile.length());
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=\""+ taskResultExcel + "\"");
response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
return SUCCESS;
}
public String download() {
HttpServletResponse response = getResponse();
String flag = SUCCESS;
log.info("下载的文件为: " + downloadFile);
try {
String filePath2 = ServletActionContext.getServletContext().getRealPath("/"); //取当前系统路径
// path是指欲下载的文件的路径。在path 路径下创建名为
// File file = new File(filePath2 + "zjh/下载.xls");
File file = new File(filePath2 + downloadFile);
if (!file.exists()){
log.info("文件没有找到:" + downloadFile);
flag = null;
}
// 取得文件名。
String filename = file.getName();
// 取得文件的后缀名。
String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
// 以流的形式下载文件。
// InputStream fis = new BufferedInputStream(new FileInputStream(filePath2 + "zjh/下载.xls"));
InputStream fis = new BufferedInputStream(new FileInputStream(new File(filePath2 + downloadFile)));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
// 清空response
taskResultExcel = downloadFile.substring(downloadFile.lastIndexOf("/")+1, downloadFile.length());
log.info("页面文件为: " + taskResultExcel);
response.reset();
response.addHeader("Content-Disposition", "attachment;filename="+ java.net.URLEncoder.encode(taskResultExcel,"utf-8"));
response.addHeader("Content-Length", "" + file.length());
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
toClient.close();
} catch (IOException ex) {
log.info("下载文件出现异常" + ex.getMessage());
flag = null;
}
// return response;
return flag;
}
- 姚博文 下载:javax.servlet.ServletException: ClientAbortException: java.net.SocketException: Broken pipe
- javax.servlet.ServletException: ClientAbortException: java.net.SocketException: Broken pipe错误完美解决
- ClientAbortException: java.net.SocketException: Broken pipe
- ClientAbortException: java.net.SocketException: Broken pipe 异常
- ClientAbortException: java.net.SocketException: Broken pipe 的原因和测试方法
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe
- java.net.SocketException: Broken pipe异常
- java.net.SocketException: Broken pipe异常
- JedisConnectionException: java.net.SocketException: Broken pipe
- 终结IT业七大流言
- 完成端口另起一个accept线程方式
- 收藏的网站
- redis安装流程
- HTML源码:超全的“职务”下拉列表
- 姚博文 下载:javax.servlet.ServletException: ClientAbortException: java.net.SocketException: Broken pipe
- OpenCv常用函数实例
- 学习记录
- SHELL TR命令
- IOCP和SetFileCompletionNotificationModes
- Xcode4使用release报错的问题
- 存储过程初步
- C#中结构的特点
- MyBatis的动态SQL详解