• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

File Mapping from Servlet to Client

Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want help in Servlets....

My problem is, i am having one servlet and one client(Html) and one imageFile. My servlet knows the filePath, now it has to process the filePath so that the imageFile is displayed in Html. Now, the issue is in servlet is there any other procedure other than streaming the file in to ServletoutputStream??? I know that the following code solves my problem,
File f = new File("F:\\Images\\2\\3\\2004\\12282004\\08\\1.jpg");

byte[] imageData = new byte[(int) f.length()];

FileInputStream fis = new FileInputStream(f);



ServletOutputStream out = response.getOutputStream();


But what I want to know is, instead of Streaming the file into byteArray and set into ServletOutputStream, is there any other alternative???

Thanks in advance


Rama Sarma Vemuri L S K
Mobile: +91-9885584568
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a general rule you Servlet shouldn't really be outputting any HTML. I know it can, and ther are examples on Sun's site which do just that, but it makes for very unmaintainable code. You might consider JSPs.

That being said, remember that your Servlet is juts creating a static web page, and how web pages work. You don't add much be streaming the file which just including it in an <img /> tage wouldn't do anyway. So why not just serve the image as you would for a static HTML page, and link to it?
    Bookmark Topic Watch Topic
  • New Topic