使用jspsmartupload中遇到的问题
xx_ch 2004-08-30 12:10:51 我使用jspsmartupload进行文件的上传和下载
在完全按照网上的例子来写的
下载页面如下
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="com.jspsmart.upload.*" %>
<%
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 初始化
su.initialize(pageContext);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为pdf时,
//浏览器将用acrobat打开。
su.setContentDisposition(null);
// 下载文件
su.downloadFile("/upload/aa.txt");
%>
运行以后报错
java.lang.IllegalStateException: getOutputStream() has already been called for this response
我直接在页面写下载代码也出同样的错误,代码如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.io.*" %>
<%
String fileName = "aa.txt".toString();
//读到流中
InputStream inStream=new FileInputStream("/upload/aa.txt");
//设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition","attachment; filename=" + fileName );
//循环取出流中的数据
byte[] b = new byte[100];
int len;
while((len=inStream.read(b)) >0)
response.getOutputStream().write(b,0,len);
inStream.close();
%>
大家帮我看看,谢谢