使用java检索Mysql DB中的图像并显示
我有一个 Mysql 数据库,里面有图像。
现在我想检索这个数据库并使用java代码在网页中显示图像。
谁能提供这个的代码吗?? 至少建议这样做???
提前致谢..!!
I have a Mysql database with the images in it.
Now I want to retreive this database and display the images in a web page using java code.
Can anyone provide the code for this??
Atleast suggestions to do this???
Thanks in advance..!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个 servlet 来处理这个问题。让我们用 URL 路径
/Image
来调用它ImageServlet
在 servlet 的
doGet
方法中编写代码来读取一个名为的参数>name
来自请求并执行 SQL。SQL 应该从表中获取 blob。我不记得语法了,但最终你会得到一个
byte[]
,你必须将其写入响应流中。在 JSP 中,您将像这样调用它:
下面的链接应该让您开始编写 SQL 来读取 blob:
http://www.jguru.com/faq/view.jsp?EID=第1325
章/imageservlet.html#ImageServletServingFromDatabase - 归功于 BalusC
Create a servlet to handle this. Lets call it
ImageServlet
with the URL path/Image
Write code in the
doGet
method of the servlet to read a parameter called, say,name
from the request and execute an SQL.The SQL should fetch the blob from your table. I can't remember the syntax, but ultimately you will end up with a
byte[]
which you'll have to write into your response stream.In your JSP, you will invoke it like this:
<img src="/Image?name=logo.jpg" />
This links below should get you started writing SQLs to read from blobs:
http://www.jguru.com/faq/view.jsp?EID=1325
http://balusc.blogspot.com/2007/04/imageservlet.html#ImageServletServingFromDatabase - with due credit to BalusC