httpservletresponse 返回图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
("/image/foo.jpg")
public void (HttpServletResponse response) {
InputStream in = null;
OutputStream out = null;

try {
response.setContentType("image/png");
in = new FileInputStream("/imageDir/foo.jpg");
out = response.getOutputStream();
IOUtils.copy(in, out);
} catch (Exception ex) {
logger.warn(ex.getMessage());
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}