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() + "\"");
有人可以回答這個問題嗎? – NaiveCoder