2008/9/27 Dave <[EMAIL PROTECTED]>:
> 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.
>

You do not close the streams properly, thus they disappear without
being flushed.

Read at least the Java Tutorial at java.sun.com [1]. Pay attention to
the "finally" keyword.

[1] http://java.sun.com/docs/books/tutorial/essential/index.html

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to