在jsp将byte[]输出图片

//
byte[] imageData = (byte[]) ImageUtil.getImage(...);
				
				
				response.setContentType("image/png");
				OutputStream output = response.getOutputStream();
				InputStream in = new ByteArrayInputStream(imageData);
				int len;
				byte[] buf = new byte[1024];
				while ((len = in.read(buf)) != -1) {
					output.write(buf, 0, len);
				}
				output.flush();
//如果没有下面两行,可能出现getOutputStream() has already been called for this response的异常
				out.clear();
				out = pageContext.pushBody();
 

你可能感兴趣的:(jsp)