开发者

Retrieving the images in Mysql DB and display using java

I have a Mysql database with t开发者_运维技巧he 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..!!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜