使用java检索Mysql DB中的图像并显示

发布于 2024-10-20 06:12:51 字数 116 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好多鱼好多余 2024-10-27 06:12:52

创建一个 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文