java远程文件转成输入流之后写给浏览器,达到下载该文件的效果,在window中运行正常,linux中无法下载
在windows中的tomcat 5.5 中运行是正常下载,但是部署到服务器中(linux的tomcat 5.5)就有异常,下载的文件大小为0,问题比较难定位,求大神解释
代码如下:
is = ftp.getInputStream(appUrl);
if (null != is)
{
response.reset();
response.setContentType("application/x-download;charset=gb2312");
response.setHeader("Content-Disposition", "attachment;filename=\"" + java.net.URLEncoder.encode(appName,"UTF-8") + "\"");
response.setCharacterEncoding("GBK");
response.resetBuffer();
response.flushBuffer();
bis = new java.io.BufferedInputStream(is);
os = response.getOutputStream();
byte[] bys = new byte[1024];
boolean isCancel = false;
int tt;
while((tt=bis.read(bys)) != -1)
{
try
{
os.write(bys, 0, tt);
}catch(Exception e)
{
isCancel = true;
break;
}
}
if (!isCancel)
{
os.flush();
os.close();
os = null;
}else
{
try
{
if (null != os)
{
os.close();
}
}catch(Exception e)
{
}
os = null;
}
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}else
{
out.clear();
out = pageContext.pushBody();
}
}catch(Exception e)
{
out.clear();
out = pageContext.pushBody();
}
jsp
java
------解决方案-------------