【发布时间】:2017-01-05 07:08:56
【问题描述】:
我已经在我的 Spring mvc 项目中实现了文件下载,在下载文件时它在 tomcat 7 服务器上给了我以下错误:
org.apache.coyote.http11.HeadersTooLargeException: An attempt was made to write more data to the response headers than there was room available in the buffer.
Increase maxHttpHeaderSize on the connector or write less data into the response headers.
我还尝试使用 server.xml 中的以下代码增加标头大小
<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />
但是,这也不起作用,我仍然收到上述错误。
以下是文件下载的控制器代码:
@RequestMapping(value = "/admin/file/download", method = RequestMethod.GET)
public @ResponseBody ModelAndView download(HttpServletRequest request,
HttpServletResponse response) throws Exception {
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
Files file = this.filesManager.find(id);
response.setContentType(file.getType());
response.setContentLength(file.getFile().length);
response.setHeader("Content-Disposition", "attachment; filename=\""+ file.getFilename() + "\"");
FileCopyUtils.copy(file.getFile(), response.getOutputStream());
response.flushBuffer();
return null;
}
Files 类存储数据库中的文件信息:
public class Files {
private int id;
private String filename;
private String type;
private byte[] file;
}
我也尝试删除以下行,但仍然出现相同的错误:
response.setHeader("Content-Disposition",
"attachment; filename=\""+ file.getFilename() + "\"");
【问题讨论】:
-
有人能回答这个问题吗?
标签: java spring-mvc tomcat download http-headers