简体   繁体   English

显示响应图像

[英]Display image from response

I have write the image into httpresponse , I defined the contentType for the image. 我已经将图像写入httpresponse ,为图像定义了contentType

response.getOutputStream().write(imageBytes);
response.getOutputStream().flush();

What is the syntax to display this image in jsp? 在jsp中显示此图像的语法是什么?

You can use base64 encoding for this. 您可以为此使用base64编码。 For this you'll need to encode it as base64 on the server side and embed that on client side as - 为此,您需要在服务器端将其编码为base64,并在客户端将其嵌入为-

<img src="data:png;base64,base64_encoded_image_here"> 

Of course, png can be replaced with appropriate mime_type. 当然,可以用适当的mime_type替换png。 The downside it that the image will be part of the HTML content. 缺点是图像将成为HTML内容的一部分。 But there won't be a separate HTTP request for this image. 但是此图像不会有单独的HTTP请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM