2016-08-29 97 views
2

我在Spring MVC中的项目implmented文件下载,并在下载的Tomcat 7服务器上它给了我下面的错误文件:HeadersTooLargeException - 响应头

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; 

} 

类文件存储从数据库中的文件信息:

public class Files { 
    private int id; 
    private String filename;  
    private String type; 
    private byte[] file; 
    } 

我也试着删除下面的线,但仍然给出了同样的错误:

 response.setHeader("Content-Disposition", 
"attachment; filename=\""+ file.getFilename() + "\""); 
+0

有人可以回答这个问题吗? – NaiveCoder

回答

1

我有类似的问题。在我的情况下,响应对象的标题确实太多,它们的总长度超过了maxHttpHeaderSize。尝试使用调试器检查响应对象:在Tomcat上,它可能包含一个coyoteResponse对象,该对象具有headers字段。也许你会发现一些无关设置Cookie标题或类似?