Hi Folks

I have a problem when a user downloads a file,  my
code works fine when
the user selects save on the box which pops up on
their browser.  However
there are problems when the user selects cancel.  What
I have is

    response.setHeader("Content-Disposition",
                      "inline; filename=\"" + fileName
+ "\"");
    response.setContentLength((int)f.length());
   FileInputStream fin;
    ServletOutputStream out =
response.getOutputStream();
    BufferedInputStream data = new
BufferedInputStream(fin = new

FileInputStream(getFileName()));
    byte[] buf = new byte[4 * 1024]; //4kb buffer
    int len;
    while( ( len = data.read(buf, 0, buf.length)) !=
-1 )
   {
          out.write(buf, 0, len);
   }

to send the user a file.  What seems to happen when
this servlet is run
in Tomcat is that tomcat buffers the result of
out.write().  When the
user is prompted to save the file and clicks cancel
download an exception
is thrown.  I want to display
an error page, but I have already sent a response, so
when I do

        catch(Exception e)
        {
            PrintWriter out = response.getWriter();
            response.setContentType("text/html");
            ServletContext context =
getServletContext();
           out.println("An error occured. Please
contact the site administrator");
        }

I get the exception
2001-07-19 01:29:14 - Ctx( /default ):
IllegalStateException in:
R( /default + servlet/processAccount + null)
OutputStream is already being used for this request

What can I do to handle the case when the user cancels
the download?

Cheers

Tony

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.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

Reply via email to