Hi in ur code use this
PrintWriter out = new PrintWriter(response.getOutputStream());
instead of
ServletOutputStream out = response.getOutputStream();
thx
pradeep
>From: gutschi <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: File downloading...
>Date: Sun, 26 Nov 2000 16:08:57 +0100
>
>Hello all y'all,
>
>i want to write a servlet that enables the user to download a file; i'm
>using the following code to do this but i get an IllegalStateException
>while
>executing it. Any ideas what might be wrong?
>
>The code fragment:
>
>public void service(..) ... {
>
> String filename = request.getParameter("file");
> FileInputStream fis = new FileInputStream(filename);
> BufferedInputStream bis = new BufferedInputStream(fis);
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> int ch;
> while ((ch = bis.read()) != -1) {
> baos.write(ch);
> }
> byte buffer[] = baos.toByteArray();
> response.setContentType("application/octet-stream");
> response.setHeader("Content-Disposition", "attachment;filename=" +
>filename);
> ServletOutputStream out = response.getOutputStream();
> out.write(buffer);
>}
>
>Thanks in advance for your ideas.
>
>Michael Weller
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html