且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在servlet中使用inputstream显示图像?

更新时间:2023-12-03 23:40:58

您需要将图像作为字节数组写入响应的输出流。这样的事情:

You need write the image as a byte array to the response's output stream. Something like this:


byte [] imageBytes = getImageAsBytes();

响应。 setContentType(image / jpeg);

response.setContentLength(imageBytes.length);

response.getOutputStream()。write(imageBytes);

然后在JSP中你只需使用一个标准的img元素:

Then in you JSP you just use a standard img element:

<img src="url to your servlet">

资料来源: https://***.com/a/1154279/1567585