It's not a secret anymore!
The moose likes Servlets and the fly likes Display images and text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Display images and text" Watch "Display images and text" New topic

Display images and text

Adnan Badar

Joined: May 07, 2003
Posts: 6
Hello All,
I have to display jpg files placed in some real path(not in web context). Along with images i also have to display header and footer text. I am unable to display both images and text together. I am using this code:
public void doGet() {
File f = new File("D:\\ImageArchive\\file1.jpg");
com.sun.image.codec.jpeg.JPEGImageDecoder decoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(new FileInputStream(f));
java.awt.image.BufferedImage image =decoder.decodeAsBufferedImage() ;

javax.servlet.ServletOutputStream sos = response.getOutputStream();
com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(sos);
Thanks in advance....
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

I don't see anywhere in your code where you actually write to the response, but in any case, no, you cannot mix images and text.
What you CAN do, is to generated HTML with text and image tags that reference the image. To serve images that cannot be addressed via URL, I'd write a servlet that can read and serve the image (and only the image) and reference that in the src attribute of your image tags.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Display images and text
It's not a secret anymore!