reading byte image from database in servlet and displaying it in jsp page

Hi experts,

I have saved my image data in the my database (ms sql server 2000).

Now I am reading in the bytes from the database in ejb. I am access this in a servlet. Now I want access this in my jsp page. How can I do this.

Heres my servlet code:

response.setContentType("image/jpeg");

response.setHeader("pragma", "no-cache");

ServletOutputStream out = response.getOutputStream();

out.write(content.getContentObj());

out.close();

Please help me.

Thanx...

Deepak

[543 byte] By [deepak@stara] at [2007-11-27 4:52:04]
# 1
This code snippet is incomplete, but the actual code looks OK.Which problems are you occurring then?
BalusCa at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi all,I am able to solve the problem but I got another problem now.There are a number of images stored in the database. I want to display all the images on the jsp page. Please help me of how about going to do this.Thanx...
deepak@stara at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Represent each and every image stored inside the db by a unique imageid and while querying use imageid and retrive appropriate Blob field. and here is how you call an image servlet while gives you image reponse.

<table>

<tr>

<td><image src="ImageServlet?imageid=1"/></td>

<td><image src="ImageServlet?imageid=2"/></td>

<td><image src="ImageServlet?imageid=3"/></td>

</tr>

<tr>

<td><image src="ImageServlet?imageid=4"/></td>

..................................

..................................

</tr>

</table>

Hope that might help :)

REGARDS,

RaHuL

RahulSharnaa at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
I was assuming that he already have created kind of an ImageServlet, where this code snippet is from.If it is not actually true you may find those ImageServlet examples useful: http://balusc.xs4all.nl/srv/dev-jep-img.html
BalusCa at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanx guys...This is working fine now.Just another question I have. On the pages I want to put links which on click gets you to download the images to the client machines.Please help..Thanx...Deepak
deepak@stara at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

You can reuse the code, but just replace the contentdisposition 'inline' by 'attachment'. Also see the several downloadFile() snippets at the bottom of this article: http://balusc.xs4all.nl/srv/dev-jep-pdf.html Use this in kind of a FileServlet, which can be created and used almost the same way as ImageServlet.

BalusCa at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
HiThat article explains about how to open a PDF file in a new window.I want to have links on the page, which on click starts to download the image file on client machines...Please help me with this.....regards ....deepak
deepak@stara at 2007-7-12 10:05:57 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Then you don't understand me or even the code.I'll tell it once more again: see the several downloadFile() snippets at the bottom of this articleThat's it.
BalusCa at 2007-7-12 10:05:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Hi guys, Actually i want to upload a image file and save it into a mysql db,using jsp. And i want to open the image in browser(retreving img from db).If u have any idea, plz reply this topic.
SARAV_RSa at 2007-7-12 10:05:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Don't hijack other's topics. Upload examples can be found [url= http://www.google.com/search?q=jsp+file+upload]here[/url] and displaying images using a servlet is linked here above.
BalusCa at 2007-7-12 10:05:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
HiThanx guys for helping me....I got this working now...Actually I used following in my coderesponse.setHeader("Content-Disposition", "attachment;filename=\""+saveFile+"\"");Thanx...Deepak
deepak@stara at 2007-7-12 10:05:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
Hi, I want to check today's date to after 2 days. i.e, after 2 days(from today's date) it will trigger some functions.how to check the condition?
SARAV_RSa at 2007-7-12 10:05:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
Don't hijack topics. Proceed here http://forum.java.sun.com/thread.jspa?threadID=5176516
BalusCa at 2007-7-12 10:05:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...