问题描述
- jsp文件下载的问题,RequestDispatcher的方式
-
我用RequestDispatcher的方式进行文件下载,为啥每次都只能下载20%就下载失败了
代码如下:
<%response.setContentType("application/octet-stream");
String filedownload = request.getParameter("filePath_KC");
String filedisplay = request.getParameter("fileName_KC");
String filenamedisplay = URLEncoder.encode(filedisplay,"UTF-8");response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
try
{
RequestDispatcher dis = application.getRequestDispatcher(filedownload);
if(dis!= null)
{
dis.forward(request,response);
}
response.flushBuffer();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
}
解决方案
不用这句。response.flushBuffer();
时间: 2025-01-20 13:36:57