File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Upload Image in a JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Upload Image in a JSP Page" Watch "Upload Image in a JSP Page" New topic

Upload Image in a JSP Page

Natasha Sirat

Joined: Jan 20, 2006
Posts: 2
Hello Everyone,

I need some advice on Image Upload in JSP's. I am currently working on an application where I have the image data available to me in a Byte[].

We are using the following packages to implement Image Upload:

The FormFile object is converted into a byte[] by using the getFileData() method.

After the user selects the image to be uploaded and clicks OK:

1) We need to display the image in the same browser window in a thumbnail view.
2) We need to display this image on the next page also after the user submits his POST operation.

Currently I was trying to read about memorystreams in order to convert this image byte[] in to a image format to be dispalyed on the webbrowser.

We are using JSP, Pageflow, Weblogic 8.1 to develop this application.

Also we need to display this image from the memory first. As the image will be saved on the remote server only after the user chooses to publeh the AD untill such time we want to display the image in the browser window.

That is the reason I was thinking about MemoryStreams().

Do let me know what is the best way to handle images.

Thank you very much

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Natasha S,
Welcome to JavaRanch!

We're pleased to have you here with us in the JSP forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here
[ January 20, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Natasha Sirat

Joined: Jan 20, 2006
Posts: 2
Sure...Thank you for letting me know...

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Remember that JSP are for character output - images are binary data which can NOT be served correctly in a character stream. Your JSP must write an IMG tag in the HTML output where the src refers to a servlet that can format the correct response for the image request. This topic comes up frequently, browse around in recent posts.
I agree. Here's the link:
subject: Upload Image in a JSP Page
It's not a secret anymore!