添加响应头:
response.addHeader("Content-Disposition", "attachment; filename=" + response.encodeURL(downloadfile));
private void genCode(HttpServletResponse response, byte[] data) throws IOException { response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); }