473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Displaying an image in JSP

Hi,
I have an image, in JPEG format, stored inside a byte array.
I have to render that image. I will not be able to open a file
connection and write that image to HDD, either on client side or on
server side. So my query is this, how do I render an image which is
stored as a series of bytes? I have tried out.println and IMG tag, but
they do not work.

Any help would be appreciated

Bye
Amardeep Verma
Jul 17 '05 #1
6 21729
presumably your JSP page is currently producing HTML. HTML cannot contain
image data in the file itself, only through an external href.

so the best option would be to generate an <img> tag in your JSP which
contains a URL to a different JSP (or the same jsp with different
parameters). When the browser requests the image, you can send the binary
data as content type image/jpeg.

Andy
"Amardeep Verma" <ad******@email.com> wrote in message
news:1a**************************@posting.google.c om...
Hi,
I have an image, in JPEG format, stored inside a byte array.
I have to render that image. I will not be able to open a file
connection and write that image to HDD, either on client side or on
server side. So my query is this, how do I render an image which is
stored as a series of bytes? I have tried out.println and IMG tag, but
they do not work.

Any help would be appreciated

Bye
Amardeep Verma

Jul 17 '05 #2
"Amardeep Verma" <ad******@email.com> wrote in message
news:1a**************************@posting.google.c om...
Hi,
I have an image, in JPEG format, stored inside a byte array.
I have to render that image. I will not be able to open a file
connection and write that image to HDD, either on client side or on
server side. So my query is this, how do I render an image which is
stored as a series of bytes? I have tried out.println and IMG tag, but
they do not work.


I haven't tried this, but my guess is that you could include a tag like this
in your html: <img src="myimage.jsp">. Then have myimage.jsp return the byte
data. Be sure to set the http response header to indicate that it's a jpeg.


Jul 17 '05 #3
On 1 Aug 2003 00:10:55 -0700, ad******@email.com (Amardeep Verma)
wrote or quoted :
So my query is this, how do I render an image which is
stored as a series of bytes?


see http://mindprod.com/jgloss/image.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Jul 17 '05 #4
Chris wrote:
"Amardeep Verma" <ad******@email.com> wrote in message
news:1a**************************@posting.google.c om...
Hi,
I have an image, in JPEG format, stored inside a byte array.
I have to render that image. I will not be able to open a file
connection and write that image to HDD, either on client side or on
server side. So my query is this, how do I render an image which is
stored as a series of bytes? I have tried out.println and IMG tag, but
they do not work.

I haven't tried this, but my guess is that you could include a tag like this
in your html: <img src="myimage.jsp">. Then have myimage.jsp return the byte
data. Be sure to set the http response header to indicate that it's a jpeg.

FYI, since JSPs implicitly open the output stream as a character stream
and the specification prohibits one from re-opening it as a byte stream,
this is best done from a servlet instead of a JSP.

Ray

Jul 17 '05 #5
Allen E. Scharfenberg wrote:
I think you can set the MIME type you are returning in both servlets and
JSP. SO, you could set the MIME type being returned to image\jpeg or
whatever, convert the byte[] to a character[], and then just slam it
through.


No; you can set the MIME type if you like, but a JSP is only allowed to
return character data. There was a tech tip from Sun a while back that
dealt with this very issue. The original tip suggested using JSPs, but
the next tip made the correction. In fact, I just found the tip in my
email library; it wasd the tech tip for 8/21/2001.

Here are the links:
http://developer.java.sun.com/develo...01/tt0821.html
http://developer.java.sun.com/develo...21_update.html

Ray

Jul 17 '05 #6
Allen E. Scharfenberg wrote:[color=blue]
> I think you can set the MIME type you are returning in both servlets and
> JSP. SO, you could set the MIME type being returned to image\jpeg or
> whatever, convert the byte[] to a character[], and then just slam it
> through.
>[/color]

No; you can set the MIME type if you like, but a JSP is only allowed to
return character data. There was a tech tip from Sun a while back that
dealt with this very issue. The original tip suggested using JSPs, but
the next tip made the correction. In fact, I just found the tip in my
email library; it wasd the tech tip for 8/21/2001.

Here are the links:
http://developer.java.sun.com/develo...01/tt0821.html
http://developer.java.sun.com/develo...21_update.html

Ray
Hi Ray

Thanks a lot. You solved my problem. I was thinking along the same lines on setting the mime type on jsp response. These URLs showed how to do it exactly.
Jul 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
2
by: marvin | last post by:
Hi, I am trying to display images in a repeater from a SQL database and do some transformations on the image prior to displaying them (such as thumbnail with a shadow). The problem is I can't...
3
by: CD | last post by:
An application is logging faxes sent in SQL2000 image column type. I have found code on the net but what it is doing is prompting to save to local which is fine for single page image. Not good...
5
by: ljuljacka | last post by:
I'm trying to display resized images. Locations of images are fetched from database. The problem is that with the following code, I get only the first image displayed: <?php...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
4
by: shahidrasul | last post by:
i display a pic on picture box and then i want to display another pic after some seconds but problem is that first image is not displaying only display 2nd image 1... display first picture from...
6
by: Jeff | last post by:
hi asp.net 2.0 I have a image (.jpeg) stored in sql server 2005 and now I want to display it on a webpage. So I created a webpage (Image.aspx) which just writes the buffer data to the...
3
by: mvijayrkumar | last post by:
Hi to all.... Guys pls help me..... I have an image issue in RLDC while hosting my project on server.The image displays or works fine with the local system.But when hosted on server,both the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.