即使我的控制器方法中没有错误,我也无法从浏览器下载excel文件.
@RequestMapping(value = "/getExcelFile", method = RequestMethod.GET, produces="application/json")
public @ResponseBody HttpEntity<byte[]> getUserDetailsExcelFile(@RequestParam Long id) {
try {
byte[] wb = ExcelReportView.buildExcelDocument(data);
HttpHeaders header = new HttpHeaders();
header.setContentType(new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
header.set("Content-Disposition",
"attachment; filename=test.xls");
header.setContentLength(wb.length);
return new HttpEntity<byte[]>(wb, header);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
我收到了来自firebug的信息请求.
Request Method:GET Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:org.cups.sid=ed8f7540d976ccc90b85954f21520861; org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=fr; __ngDebug=true; JSESSIONID=tqi3ofownl17
Host:localhost:8888
Referer:http://localhost:8888/
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like …Run Code Online (Sandbox Code Playgroud)