public class CooikeController {
@RequestMapping("response")
public String cookieTest( HttpServletResponse response ) throws IOException {
ServletOutputStream outputStream = response.getOutputStream();
String filename = "yuanyaun.jpg";
//如果这里不设置的话,将会在页面上直接展示图片
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
File file = new File("D:\\360downloads\\298277.jpg");
response.addHeader("Content-Length", "" + file.length());
FileInputStream fileInputStream = new FileInputStream(file);
IOUtils.copy(fileInputStream,outputStream);
response.setContentType("application/octet-stream");
outputStream.flush();
return "womenhao";
}
}
如何在页面展示和下载图片
最新推荐文章于 2021-05-13 17:54:51 发布