<%@ page contentType="application/x-msdownload;charset=UTF-8" import="com.jspsmart.upload.*,java.io.File"%>
<%
String filename = request.getParameter("filename");
String resultdir = (String) request.getAttribute("resultdir");
File file = new File(resultdir, filename);
//新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 初始化
su.initialize(pageContext);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
// 保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
// doc时,浏览器将自动用word打开它。扩展名为pdf时,
// 浏览器将用acrobat打开。
// 下载文件
su.setContentDisposition(null);
su.downloadFile(file.getAbsolutePath());
// 如果是小文件加上这句就能处理
response.getOutputStream().close();
%>
写一个SmartUpload下载,下载大文件大约10K没问题,但是1K左右的小文件就会报异常:java.lang.IllegalStateException: getOutputStream() has already been called for this response
我在JSP页面的最后加了一句“response.getOutputStream().close();”,问题解决。