@RequestMapping(value = "/t20/reportDownload", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@ResponseBody
public String reportDownload(HttpServletRequest request, HttpServletResponse response) {
return t20Service.reportDownload(request, response);
}
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
response.getOutputStream().write(pdfbytes);
response.getOutputStream().flush();
return "successfully";
不能使用ajax, 因为它返回的是字符格式, 有时候不弹出下载框
$.ajax({
url:"/down/downExcel",
type:"GET",
dataType:"json",
success:function(result){
}});
使用 window.location.href="/down/downExcel";