Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JSP Interest »

Re: how to display image from mysql using jsp

Emmanuel Eze

2004-07-03

Replies:

Image display is better done via a servlet.

My advice in this case is to write a generic servlet for image display which
will retrieve any image from ur DB based on the parametes passed to it. All u
need do is write your normal jsp or html and call this servet whenever u need
an image to be diplayed. A sample call will look like this:

<img WIDTH=120 HEIGHT=120 src=ShowImage?urparamaters>

Alternatively, u may still achieve everything in one jsp though it is not a
good approach. Ur jsp will look like ur servlet code but u must send outpout to
ServletOutputStream and not ur usual out object. eg

javax.servlet.ServletOutputStream cout = response.getOutputStream();

I assume u know u must set response.setContentType() to the right mime type.

Hope this helps?

Cheers!

Emmanuel Eze

Quoting lee hwaying <hwayinglee@(protected)>:

> hi.
>
> i have search on the net for 3 days for sample code of displaying a byte[]
> from mysql image field using jsp but without success.
>
> 1. I have found sample code for php in doing that
> http://www.onlamp.com/pub/a/onlamp/2002/05/09/webdb2.html?page=1
>
> 2. It can be done via servlet. But i am reluctant to emit all html content
> using servlet in this case.
>
>
> Can anyone help? Is there a way using jsp to do so?
>
> many many thanks
> hy
>
> _________________________________________________________________
> Download ringtones, logos and picture messages from MSN Malaysia
> http://www.msn.com.my/mobile/ringtones/default.asp
>
> ===========================================================================
> To unsubscribe: mailto listserv@(protected)
> JSP-INTEREST".
> For digest: mailto listserv@(protected)
> DIGEST".
>
> Some relevant archives, FAQs and Forums on JSPs can be found at:
>
> http://java.sun.com/products/jsp
> http://archives.java.sun.com/jsp-interest.html
> http://forums.java.sun.com
> http://www.jspinsider.com
>
>




-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
from the University of Hull Centre for Internet Computing
http://www.cic.hull.ac.uk/

===========================================================================
To unsubscribe: mailto listserv@(protected)".
For digest: mailto listserv@(protected)".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com
©2008 junlu.com - Jax Systems, LLC, U.S.A.