• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display images and text

 
Adnan Badar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic