/**
* 通过servlet查看图片
* @param datas
* @param imgType
* @param response
* @throws IOException
*/
public void viewPic(byte[] datas, String imgType, HttpServletResponse response) throws IOException {
InputStream buffin = new ByteArrayInputStream(datas);// 业务逻辑取得图片的byte[]
ServletOutputStream sos =null;// 将图像输出到Servlet输出流中。
try {
BufferedImage img = ImageIO.read(buffin);
// 禁止图像缓存。
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
sos = response.getOutputStream();// 将图像输出到Servlet输出流中。
ImageIO.write(img, imgType, sos);
} catch (IOException e) {
e.printStackTrace();
} finally {
buffin.close();
sos.close();
}
}
参考文章:http://blog.csdn.net/sunny243788557/article/details/7903615