如何在JSF中显示数据库中的图像 [英] How to display images from database in JSF
问题描述
我有一些图像以BLOB形式存储在数据库中.现在,我可以使用Richfaces mediaOutput标签在我的jsf页面中显示它们.
I have images that are stored in the database as a BLOB. Now I can display them in my jsf pages using Richfaces mediaOutput tag.
当图像存储在数据库中时,图像是否可能具有"/images/image.jpg"之类的路径.
Is it possible for images to have path like "/images/image.jpg" while images are stored in the database.
在寻找答案时,我遇到了如下问题:
While searching for an answer I came around something like this:
@GET
@Path("/files/{filename}")
@Produces(MediaType.WILDCARD)
最诚挚的问候, 伊利亚·西多罗维奇(Ilya Sidorovich)
Best regards, Ilya Sidorovich
推荐答案
您可以编写一个Servlet来处理对/image/*
或适合您的每个请求.
在Servlet中,您可以通过请求参数从数据库中检索正确的数据.
然后通过
You could write a servlet picking up every request to /image/*
or something that suits you.
And in your servlet you retrieve the correct data from your database via request parameters.
And you write out the data via
response.getOutputStream().write(content);
(内容是您图像的字节数组)
(content being the bytearray of you image)
这篇关于如何在JSF中显示数据库中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!