欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

java 返回图片到页面_html/css_WEB-ITnose

程序员文章站 2024-01-28 22:38:10
...
@RequestMapping(value = "/image/get")
public void getImage(HttpServletRequest request,HttpServletResponse response) {
FileInputStream fis = null;
response.setContentType("image/gif");
try {
OutputStream out = response.getOutputStream();
File file = new File("D:"+File.separator+"timg.jpg");
fis = new FileInputStream(file);
byte[] b = new byte[fis.available()];
fis.read(b);
out.write(b);
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}