全部展开
1、response.reset (; 不应该去重置
2、请参考我以前写的下载这个pdf的文件。 e 68 a 84 e8a 2ad 3231331335323631343130323136331333133333332623963可以解决楼主的问题,我们稍作改动。 servletoutputstreamout=RES.get output stream (;
//为了解决下载后的中文乱码
字符串内容类型=get content type (fileext;
//contentType=contentType '; charset=gbk ';
res.setcontenttype(contenttype );
System.out.println (显示下载的名称为----------- )
时间;
stringcontentheader=' attachment '; “' filename=”
urlencoder.encode(temp,' UTF-8 ' ) );
RES.setheader (' content-disposition ',contentHeader );
system.out.println (contentheaderis=' content header );
//intMAX_FILE_SIZE=3*1024*1024; //在此设定文件的最大大小。 关于本程序,不设定就可以了。 3M
intbyte_unit=1024;
//byte [ ] buffer=new byte [ max _ file _ size ];
byte [ ] buffer=new byte [ byte _ unit ]; //一次读取的文件的数据长度
intlength=0;
while((Length=is.read ) ) Buffer!=-1({
out.write(buffer,0,length );
}
if(is!=null )
is.close (;
if (出局!=null ) {
out.flush (;
out.close (;
}
//获取内容类型
私有状态字符串内容类型(字符串文件) )。
字符串内容类型=' ';
if(fileext==null ) ) )。
contentType=' ';
elseif(fileext.equals ) (doc ) )
content type=' application/ms word ';
elseif(fileext.equals ) (pdf ) )
contentType='application/pdf ';
elseif(fileext.equals ) (jpg ) )
contentType='image/jpeg ';
else if (fileext.equals (gif ) )
contentType='image/gif ';
elseif(fileext.equals('BMP ' ) )
contentType='image/bmp ';
elseif(fileext.equals('txt ' ) )
contentType='text/plain ';
elseif(fileext.equals ) (xls ) )
content type=' application//-excel ';
返回内容类型;
}