aspose file tools*
The moose likes Servlets and the fly likes DIsplaying Image on JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "DIsplaying Image on JSP" Watch "DIsplaying Image on JSP" New topic
Author

DIsplaying Image on JSP

Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
Hi there,
I am currently trying to display an image that was converted from byte array in the servlet and then push it and display in the jsp site. Does anyone have any idea how to do this?

Thanks in advance for helping
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
You can try something like



[ July 11, 2006: Message edited by: ak pillai ]

java j2ee job interview questions with answers | Learn the core concepts and the key areas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Originally posted by Yans Tan:

I am currently trying to display an image that was converted from byte array in the servlet and then push it and display in the jsp site. Does anyone have any idea how to do this?


Remember, once it gets to the browser, a JSP page is just like any other normal HTML page.

So if you wanted to display an image in an HTML page, how would you do it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
Originally posted by Bear Bibeault:


Remember, once it gets to the browser, a JSP page is just like any other normal HTML page.

So if you wanted to display an image in an HTML page, how would you do it?


Hi there, thx for the advice. I think I have to apologise for giving a bad title to my post. I think the problem I am facing now is more of how to send the data over to JSP rather than displaying it.
Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
Hi there, sorry to trouble you guys again. I think my english is bad, sorry about it. I think i should list out what I am doing in point form, hope this helps

1) Servlet recieves XML info containing Base64 of the image.
2) Servlet interpretes XML and converts Base64 to byte array.
3) Servlet sends byte array through http response to JSP<< This is the part which i faced my problem.

Thx again for all the troubles!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

What are you planning on doing with the data once you get it to the JSP?
Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
Display it as an image. Not sure if any conversions are needed?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

So we go back to my first question.

In a "normal" HTML file, you don't mix up the text markup and image data, do you?

Since JSP sends an HTML page to browser, how do you plan to display the image data in that HTML file?
Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
My original plan was to convert from
Base64 >> byte array >> Image object

But I do not know how to display it in JSP. So there is no solution to this? Thx again for all the follow ups
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

It can be done, but not in the way you are planning.

On your JSP page -- which will turn into an HTML page when sent to the browser -- you need to create an <img> tag that references the URL of a servlet that will serve up the image data (along the lines of what ak posted earlier).

You can't just send image data along with the HTML markup.
Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
Thanks alot man! Its up and running
Yans Tan
Greenhorn

Joined: Jul 11, 2006
Posts: 29
Problem solved thx to Bear Bibeault and ak again.

I announce thread closed
 
 
subject: DIsplaying Image on JSP