For <img src="http://domain.com/servlet/pictures/image.jpg"/>
 
in servlet get method,
 
InputStream is = new FileInputStream("/apphome/pictures/image.jpg");
OutputStream os = response.getOutputStream();
 
byte[] buffer = new byte[256*1024];  //256k
while (true) {
     int n = is.read(buffer);
     if (n < 0)
          return;
      os.write(buffer, 0, n);
}
 
is.close();
os.close();
 
 
Is this the right way? Sometimes only the half image is shown on web page. Is  
there a more efficient and robust way?  How about for audio/video files?
 
I want to take at how Tomcat does it. Could anyone tell me which class?
thanks
Dave


      

Reply via email to