473,749 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21757
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.goo gle.com...
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.goo gle.com...
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.js p">. 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.goo gle.com...
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.js p">. 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
devatha
1 New Member
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
7334
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 images as I go, without writing them to disk on the server. Do I need to prepare all of the resized images before I display the data from the select (which is put into an array by php). How can I display a resized image in a table, without writing...
3
3481
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 less would display, but those close to 300 pixels/inch or greater would not (MS Access cannot recognize the file format xxx.jpg). The larger, original images were scanned and saved as .bmp (at 300 dpi producing a 15MB file). Then the images were...
2
5229
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 seem to get the data passed to the handler. The following is the code that I have so far. In the ViewPics.aspx file I have...
3
5828
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 for multiple page faxes. I have not been able to locate an example to load in the browser or how to handle multiple image in the one column. 1) Ideally it would be nice to display back in the browser since some may be multiple images. I am not...
5
2155
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 header('Content-type: image/jpeg'); $link = mysql_connect('localhost', 'root', ''); if (!$link) {
4
2680
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 set up in the article http://support.microsoft.com/kb/285820/en-us. It works fine if the image is under 1000x1000 pixels. It is set up so the user can double click to open the image in its host application.
1
4218
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 aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
4
1687
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 database such as pbThumbImage.Image = new Bitmap(new MemoryStream(objEmployee.Picture)); 2... and then get the reference of current main thread Thread main = Thread.CurrentThread; Thread.Sleep(5000);
6
2192
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 Response object. On Default.aspx I use this Image.aspx for displaying the image, but no image
3
7732
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 images(One coming from DataSet and another from my project image folder) not displaying. Both images are having Type property External and the Values are given correspondingly.ie The One coming from Image Folder;using the Report Parameter ,the...
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.