[color=red] Stirng fileName = request.getParameter("fileName");//Redirect();[/color]
[color=red]//String fileName = request.getAttribute("fileName").toString();//forward()[/color]
try{
File file = new File(filePath);
FileInputStream bis = new FileInputStream(file);
response.reset();
response.setContentType("APPLICATION/OCTET-STREAM; charset=utf-8");
response.setHeader("Content-disposition", "attachment; filename= " + fileName);
/*response.setHeader("Content-disposition","filename=" + fileName);*/
response.setContentLength((int) file.length());
OutputStream bos = response.getOutputStream();
byte[] buff = new byte[1024];
int readCount = 0;
readCount = bis.read(buff);
while (readCount != -1)
{
bos.write(buff, 0, readCount);
readCount = bis.read(buff);
}
bos.flush();
if(bis != null)
{
bis.close();
}
if(bos != null)
{
bos.close();
}
}
catch (Throwable e)
{
//e.printStackTrace();
}finally{
out.clear();
out = pageContext.pushBody();
}
如果 是重定向到下载页面 不会出异常 但是如果forward(),
依然报getOutputStream() has already been called for this response