Problem when file download is canceled

I have been using the following code to download files in a JSP and it works fine, except if the user cancels the download once it has started. Then my application seems to be locked up and the user has to start over. I added some println statements and found that when the cancel button is pressed the code just seems to wait inside the while loop. I thought the finally clause would be called, but I guess I was wrong. Any thoughts on how to continue after a canceled download?
<%
     int size = Integer.parseInt((String)request.getAttribute("FileSize"));
     response.setContentType("APPLICATION/OCTET-STREAM");
     response.setHeader("Content-Disposition",     "attachment; filename=\"" + request.getAttribute("FileName") + "\"");
     response.setContentLength(size);
     java.io.InputStream is = null;
     try {
          is = (java.io.InputStream)request.getAttribute("File");
          int i;
          while ((i=is.read()) != -1) {
               out.write(i);
     } finally {
          out.flush();
          out.close();
          if (is != null) {
               is.close();
%>
Thanks,
- Marc

I am struggling with the same problem, does anyone know a solution to this?
Here is my code:
<%
     FileInputStream fis      = new FileInputStream(filePath + fileName);
     BufferedInputStream bis = new BufferedInputStream(fis);
     response.setContentLength(fis.available());
     response.setContentType("application/octet-stream");
     response.setHeader("Content-disposition","attachment; filename=" + fileName);
     BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
     byte[] buff = new byte[1024];
     int bytesRead;
     while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
          bos.write(buff, 0, bytesRead);
     bos.flush();
     bos.close();
     bis.close();
     fis.close();
     response.flushBuffer();
%>
please help!!

Similar Messages

  • Problem in File Download

    In some thread, i had this problem with file download that instead of opening File Save..popup, the contents of file on the server were being rendered statically as HTML. I have figured out the solution to that but now the thing is in every file, there are some \n\r being added in the beginning of the file. Can anybody help. Here's is my code.
    <%@ page import="java.io.*"%>
    <%
         try
              response.setContentType("APPLICATION/OCTET-STREAM");
              String strProjectInfoPageHeader = "Attachment;Filename=\"" + request.getParameter("txtProjectInfoPageFileName") + "\"";
              response.setHeader("Content-Disposition", strProjectInfoPageHeader);
              File fileToDownloadProjectInfoPage = new File(request.getParameter("txtProjectInfoPageFilePath"));
              FileInputStream fileInputStreamProjectInfoPage = new FileInputStream(fileToDownloadProjectInfoPage);
              int varProjectInfoPage;
              while ( (varProjectInfoPage=fileInputStreamProjectInfoPage.read()) != -1 )
                   out.write(varProjectInfoPage);
              out.flush();
              out.close();
              fileInputStreamProjectInfoPage.close();
         catch(Exception e)
              out.println(e);
    %>Thanks and regards
    Vikram

    JSPs will invariably have newlines and whitespace in them, even if you don't explicitly put them. Instead of wasting time trying to fix it, just move your code to a servlet and map it to the same path. That's the fastest and most sensible solution. It also follows the convention that JSPs are to be used for display only and servlets for processing.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
    ----------------------------------------------------------------

  • I always have problem when I download movies on the Apple Tv, I can t find them?!!

    I always have problem when I download movies on the Apple Tv, I can t find them?!!
    Can you please help me?
    Thanks

    You may wish to enable automatic downloads in your iTunes  > preferences > store settings.
    You can re-download content purchased from the iTunes store (availability varies depending on location) using the purchased option from the Quick Links section in the top right corner of the iTunes homepage in your iTunes application on your computer.

  • I have a problem when i download photoshop i downloadet it 2 days ago but i deletet it because of a virus

    i have a problem when i download photoshop i downloadet it 2 days ago but i deletet it because of a virus

    Have you already upgraded the Aperture library with version 3.4? When upgrading from Aperture 2 to Aperture 3 it is recommended to rebuild the Aperture library using the Aperture Library First Aid tools,
    see: Aperture 3 User Manual: Repairing and Rebuilding Your Aperture Library
    Léonie

  • Just upgraded to firefox 4 and websites are now taking ages to load, there were no problems when I downloaded the upgrade. Is there a fault with the new version of firefox?

    Just upgraded to firefox 4 and websites are now taking ages to load, there were no problems when I downloaded the upgrade. Is there a fault with the new version of firefox?

    Did you check your security software (firewall)?
    A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
    Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process.
    See:
    * [[Server not found]]
    * [[Firewalls]]

  • How can I reinstall Abode Acrobat Pro? Had problems when first downloaded and had to uninstall.

    How can I reinstall Abode Acrobat Pro? Had problems when first downloaded and had to uninstall.

    You can refer to :
    Acrobat Learn & Support
    Installing, uninstalling Acrobat X | Mac OS
    Adobe Acrobat X Pro * Activation and registration
    http://www.adobe.com/content/dam/Adobe/en/accessibility/products/acrobat/pdfs/acrobat-xi-p ro-accessibility-best-practice…
    They are useful resources.
    Regards
    Rajshree

  • I am using Windows XP SP3, I have problem with file download while resuming downlod giving error "file...could not be saved, because the source file could not be read." Please help me

    I am using Fire Fox 5 beta version. After pausing the long file download, when I press the Resume download button the above message appear each time asking "Contact to Administrator". This problem was not with Fire Fox version 3 and above. Please Help Immediately. Thanks in advance...

    It is possible that your anti-virus software is corrupting the downloaded files or otherwise interfering with downloading files by Firefox.
    Try to disable the real-time (live) scanning of files in your anti-virus software temporarily to see if that makes downloading work.
    * http://kb.mozillazine.org/Unable_to_save_or_download_files

  • Problem With File Download Dialog Box

    Hi all,
    I have jsp page that allows a user to export oracle data to excel.
    I have these code in my page:
    <%@ page contentType="application/vnd.ms-excel" %>
    response.setContentType ("application/vnd.ms-excel");
    response.setHeader ("Content Disposition",
    "filename=\"historicalrate.xls\"");
    I run the page and it popups a file download dialog box with Open and Save buttons.
    When I click the Save button a Save As window opens with a hr.xsl file name and Microsoft Excel Workbook(*.xls) as save type. It is what I want.
    The problem I have is when I click the Open button on the file download dialog box it displays data in excel format on a browser well. Then I click File > save as on browser's tool bar the Save As window pop up with no file name and a default Text(tab delimited)(*.txt).
    I need the file name and Microsoft Excel Workbook(*.xls) as default save type.
    Any help would be greatly appreciated.
    Please help
    Thanks

    I have the same problem with hui_ling.
    When user click on "Open", Excel start and open excel file correctly but the file name on excel title bar. 'Cause the file name is in Japanese characters. Any one can help me?
    Message was edited by:
    TNTVN

  • Problem with file download option in ALV via ITS. Please help!

    Hi Experts,
           I have a ALV report which I have web enabled using ITS service. In the ALV there is a delivered functionality for file download. It works fine when the report is run in the SE80. But when I run the ITS service for the report and choose file download option it displays a page saying "this page has been diaplayed due to technical reasons" with title "File properties". In addition it looks for Java runtime in the browser. After all this it opens a popup window for selecting path and file name.
    This is not user friendly and many customers have rasied their concerns on it.
    My question is that,
    Q1: What is the need of this "File properties page"? Why ITS calls this while ABAP editor does not?
    Q2: Is there any way we can suppress this so that it directly opens a popup window for selecting path and file name?
    Please help me.
    Thanks
    Gopal

    Hello Klaus,
    i have also the problem with these intermediate screens!
    We have in between installed patch 22 for ITS 6.20 and SP18 at SAP Netweaver 2004!
    But they are still not processed invisible for the users.
    Are there any additional parameters, which controls this behaviour(~webgui_updown_make_visible is not used!)?
    How can i check, if i have really a.ex. the actual ws.jar-file or other related files of the patch?
    We are using the standalone ITS with an own (modified) IAC with an own CI-design for the webpages. The intermediate screens are displayed with the "normal" SAPGUI-design because of the parameter ~generatedynpro. Without this it does not work, because the template SAPLSIT_0100 is missing!
    Or do you have an example for such a intermediate template with the applet for an upload of a file?
    Thanks in advance
    Felix

  • Problem with File download in ALV via ITS. Please help!

    Hi Experts,
           I have a ALV report which I have web enabled using ITS service. In the ALV there is a delivered functionality for file download. It works fine when the report is run in the SE80. But when I run the ITS service for the report and choose file download option it displays a page saying "this page has been diaplayed due to technical reasons" with title "File properties". In addition it looks for Java runtime in the browser. After all this it opens a popup window for selecting path and file name.
    This is not user friendly and many customers have rasied their concerns on it.
    My question is that,
    Q1: What is the need of this "File properties page"? Why ITS calls this while ABAP editor does not?
    Q2: Is there any way we can suppress this so that it directly opens a popup window for selecting path and file name?
    Please help me.
    Thanks
    Gopal

    Hello Klaus,
    i have also the problem with these intermediate screens!
    We have in between installed patch 22 for ITS 6.20 and SP18 at SAP Netweaver 2004!
    But they are still not processed invisible for the users.
    Are there any additional parameters, which controls this behaviour(~webgui_updown_make_visible is not used!)?
    How can i check, if i have really a.ex. the actual ws.jar-file or other related files of the patch?
    We are using the standalone ITS with an own (modified) IAC with an own CI-design for the webpages. The intermediate screens are displayed with the "normal" SAPGUI-design because of the parameter ~generatedynpro. Without this it does not work, because the template SAPLSIT_0100 is missing!
    Or do you have an example for such a intermediate template with the applet for an upload of a file?
    Thanks in advance
    Felix

  • Problem with FIle DownLoad

    Hi All,
    I am working on project where I need to display all the files (on the UI screen)which are in  windows folder with a download link.
    I used IWDDownload UI element for  downloading the file. Its working fine but problem is , when ever I download a file for first time its working fine. Later what ever I download other files, I was able to see only first file download. I guess this is problem with context binding but I am not sure.
    I used for loop to iterate all the files in folder and I binded the file name to IWD Download UI element using bindText option.I am creating UI elements dynamically in wdDoModifyView and it will call another method to bind to context.(As SAP Suggested not to modify any context elements in wdDoModifyView method).
    Please help me in this regard.
    Ramesh

    Ramesh,
    You need N dynamic binary attributes or IWDResource (in newer versions), one per file. Create them either in wdDoInit of view or in some suitable action handler.
    Then you have to populate IWDResource or set bytes of binary attributes. Check corresponding WD tutorials how to do this.
    In wdDoModifyView create IWDFileDownload control per every attribute and bind either "data" property (to binary attribute) or "resource".
    Valery Silaev

  • Problem with file downloads - please help

    Good morning. Since upgrading to BT Infinity 2, I have been experiencing the following problems:
    Cannot update Sonos firmware to version 5 - download times out and gives error 30
    Cannot download most files from safari - all start for the first few kb and then just hang
    Cannot download larger PDF files from Mac Mail
    These problems manifest themselves over wireless and wired connections, with the BT Homehub 5 and an Asus router. My ipad has no problems when on other networks or if I access my email from my work computer. When talking to BT technical support over the chat facility yesterday the connection dropped once every 10-30 seconds before reconnecting again. All of this leads me to believe that I have an intermittent failure on my broadband connection however BT insist that there is nothing wrong with the line or the router. I have changed channels on my router but this does not seem to make things better. Internet is working fine on all my devices for web browsing - only file downloads experiencing problems.
    Please help.

    Oh sorry, I thought from your description you were using an ASUS connected to the HH5, but it turns out you're using them separately.
    Is there a firmware update you can get on the ASUS?
    If you found this post helpful, please click on the star on the left
    If not, I'll try again

  • Problem in file download dialog

    Hi,
    I am using the following code to download a PDF file. (Whiich is present in the database and I am retriving it using JDBC call).
                        InputStream in = null;
                        HttpServletResponse response = ctx.response();
                        response.setContentType ("application/pdf");
                        response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
                        in = (InputStream)requestHandler.read(rparams);
                        byte[] buf = new byte[4096];
                        int len;
                        while((len = in.read(buf)) > 0)
                             out.write(buf, 0, len);
                        in.close();
                        out.flush();
                        out.close();                    
                        response.flushBuffer();
    Now when user is clicking on the specified link, file download dialog is coming, if user clicks on save the file is getting saved successfully but if user clicks on OK, it is giving the error, "There was an error opening this document. The file does not exist".
    Could anyone tell me what may be the problem in the code?
    Thanks in advance
    Amit

    Following code is returning the InputStream object:
         Blob document = null;
         QueryManager qm = null;
         int status = -1;
         InputStream dataStream = null;
         String sqlReadDocument = "select document from opr_t_aw_documents where id='"+id+"' and end_date > sysdate";
         log.debug("sqlReadDocument is "+sqlReadDocument);
              try
                   qm = new QueryManager();
                   ArrayList inParams = new ArrayList();
                   ResultSet result;
                   result = qm.performPrepQuery(sqlReadDocument, inParams);
                   if(result != null)
                        while(result.next())
                             document = result.getBlob(1);
                             if(document != null)
                                  dataStream = document.getBinaryStream();
    and out is simply response.getOutputStream().
    Please let me know in case you need any further info.
    Thanks,
    Amit

  • Major problems when first downloading tunes to a Nano

    Has anyone had problems with XP when first downloading tunes from I Tunes to a new 8GB Nano?
    My friend's PC (which is brand new and top spec) has all but locked up, with a flashing screen, really pixelated display with dots and unclear images, slow response to any command.
    Its started doing this during his initial download of tracks from I Tunes to a new 8GB Nano. Any ideas anyone?
    PS are these symptoms of the Windows RavMonE.exe virus? I assume not as this sites says Nanos were clear?

    are these symptoms of the Windows RavMonE.exe virus? I assume not as this sites says Nanos were clear?
    no nanos shipped with W32/Rjump.worm on board. but given that that particular beastie infects removable storage drives (and nanos are removable storage drives), it's plausible that you may have picked up an infection from the wild.
    you aren't reporting the usual symptoms i associate with the worm:
    http://discussions.apple.com/thread.jspa?messageID=3195362#3195362
    ... but it may be worth checking on, nonetheless.
    the names of malware tend to be specific to whatever security software identifies them. there's a list of names the worm can have in this McAfee document:
    W32/RJump.worm
    is your security software picking up anything going by one of those names?

  • SetHeader problem when user downloads a file from a server

    Hi everyone,
    I have a question about the way to let a user download a file. A created a jsp that handles the download. This is the code:
    <%@ page import="java.io.*" %><%
        response.setHeader("Content-Disposition", "attachment; filename=" + session.getAttribute("executedCommand").toString());
        response.setContentType("text/csv");
        int iRead;
        FileInputStream stream = null;
        try {
            File f = new File(session.getAttribute("executedCommand").toString());
            stream = new FileInputStream(f);
            while ((iRead = stream.read()) != -1) {
                out.write(iRead);
            out.flush();
        }finally {
            if (stream != null) {
                stream.close();
    %>When I run this, I get a download window, so that the right file can be downloaded, but I would like the application to show me the name of that file in the download window and in my save dialog, and that's something I haven't managed to do yet, because I always get the name of the servlet (that redirects to the jsp page). So the problem is, the right file is downloaded but it's name is never shown in the download window. How can I resolve that?
    Thanks for your help!
    E_J

    I forgot to say that my session variable contains the absolute path of the file the user can download. Maybe using session variables is not the best solution in this case, but it should have to work, shouldn't it?
    Still waiting for some help. I really appreciate it...
    E_J

Maybe you are looking for