aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Display images and text" Watch "Display images and text" New topic
Author

Display images and text

Adnan Badar
Greenhorn

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() {
response.setContentType("text/html");
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);
encoder.encode(image);
}
Thanks in advance....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

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.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
jQuery in Action, 2nd edition
 
subject: Display images and text