将图像保存为BLOB时如何在带有文本的JSP中显示它? [英] When saving an image as BLOB how to display it in JSP with text?

查看:156
本文介绍了将图像保存为BLOB时如何在带有文本的JSP中显示它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多谷歌搜索,但我找不到具体的答案。

I have done a lot of googling but I have not been able to find a concrete answer.

我使用Spring MVC 3将用户图像保存到数据库。我现在成功地做到了。我将图像保存为 BLOB

I am using Spring MVC 3 to save a user image to the database. I am now successfully able to do that. I am saving the image as a BLOB.

我可以将图像检索为 byte []

无论文件类型如何 - jpg,png,gif等(我的图片上传是图片文件类型不可知)我想要允许jpg和gif和png让我们说渲染即我的显示技术不应该硬编码只显示一种类型的图像,比如jpg,它应该能够显示所有图像,因为它们被上传到各自的类型 - 是要求。

Irregardless of file type - jpg, png, gif etc (My image upload is image file type agnostic) I would like to allow jpg and gif and png lets say to render i.e. my display technology should not be hard-coded to display just one type of image, say jpg, it should be able to display all images as they were uploaded in their respective types - that is the requirement.

现在,我想做2件事


  1. 如果必须,重新调整图像大小。即。
    200 by 200

  2. 使用文本在JSP中渲染图像。
    这是一个用户个人资料页面,所以我
    需要显示文字和图片

spring mvc如何使用文本渲染图像?

我从研究中了解到你可以使用 BufferedImage jsp的类型?但我的问题是,如果内容类型严格 image / jpeg image / gif

I understand from my research that you can use a BufferedImage type for the jsp? but my problem is that it seems that you can only use that if the content type is strictly image/jpeg, image/gif.

我遇到了一些调整大小的链接:

http://forum.springsource.org/archiv...p/t-46021.html

I have come across some links for resizing:
http://forum.springsource.org/archiv...p/t-46021.html

任何建议都欢迎,如果这些工作,但最终我需要显示图像。

any suggestions welcome if these work BUT ultimately I need to display the image.

请传递你的想法。

谢谢。

推荐答案

创建一个servlet,将图像从数据库流式传输到输出流的回应。然后您可以按照以下常用的HTML方式调用它:

Just create a servlet which streams the image from the DB to the outputstream of the response. Then you can just call it the usual HTML way as follows:

<p>
   <img src="imageservlet/${bean.imageId}" />
   ${bean.text}
</p>

如您所见,您只需在HTML中显示图像旁边的文字。无论如何,您无法在单个HTTP响应中混合使用它们。图像计为单独的HTTP请求。有关此类servlet的更多详细信息和启动代码示例,请查看此答案

As you see, you just display the text next to the image in HTML. You cannot mix them in a single HTTP response anyway. Images counts as separate HTTP requests. For more detail and a kickoff code example of such a servlet, check this answer.

关于调整大小,请检查Java 2D API。

As to resizing, checkout the Java 2D API.

这篇关于将图像保存为BLOB时如何在带有文本的JSP中显示它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆