使用来自字节数组的jetty Web服务器显示图像

我在一个字节数组中有一个图像的内容,在一个jetty servlet类中。 如何在浏览器中显示此图像?

你的sevlet里面会有类似的东西

byte[] imageBytes = ... response.setHeader("Content-Type", "image/jpg");// or png or gif, etc response.setHeader("Content-Length", imageBytes.lenght); response.getOutputStream().write(imageBytes); 

这段代码有效。 感谢“David Hofmann”。

 //data is the content of the image in binary response.setContentType("image/jpg");// or png or gif, etc response.setContentLength(data.length); response.getOutputStream().write(data);