Download

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radhikams
    New Member
    • Jan 2008
    • 49

    #1

    Download

    Hi
    Actually I have a functionality that can upload a file to some loaction and the name of the file to the database.
    Now I want to download that file through java struts.
    Is that possible.Can any one help me out.

    What i did is i retrieved the name of the file from databse and displayed it int the form of a table using jsp.Now i have to create a link for the file name and be able to view it
    please help me out in this regard..

    Thanks
  • radhikams
    New Member
    • Jan 2008
    • 49

    #2
    i wrote a code like this....

    File fileUpload = new File(strUploadD irectory+"\\"+s trFile_Name);
    FileInputStream fileIn = new FileInputStream (fileUpload);
    OutputStream fout=response.g etOutputStream( );
    //((ServletRespon se) fout).setConten tLength((int) fileUpload.leng th());
    byte[] buffer = new byte[8192];
    int bytesRead = fileIn.read(buf fer);

    while (bytesRead >= 0) {
    if (bytesRead > 0)
    fout.write(buff er, 0, bytesRead);
    bytesRead = fileIn.read(buf fer);
    }

    the file which i want to retrieve is comming but the problem is the actual data in the file is displayed as some other form which we cant understand...

    how to resolve this problem?????

    fout.flush();
    fout.close();
    fileIn.close();

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Have you HttpServletResp ose.setContentT ype?

      Comment

      • radhikams
        New Member
        • Jan 2008
        • 49

        #4
        Originally posted by BigDaddyLH
        Have you HttpServletResp ose.setContentT ype?

        Hi
        Thank u for the reply i tries implementing it but im getting an exception
        java.lang.Class CastException: com.planetj.ser vlet.filter.com pression.Compre ssingServletOut putStream

        what could be the problem????

        Comment

        • radhikams
          New Member
          • Jan 2008
          • 49

          #5
          Hi
          I could resolve the problem.Now its working very fine with .doc , .txt,.xls etc but there is some problem with the .pdf files... when im trying to download it is throwing this exception
          java.net.Socket Exception: Connection reset by peer: socket write error

          What could be teh problem???

          Thanks

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by radhikams
            Hi
            Thank u for the reply i tries implementing it but im getting an exception
            java.lang.Class CastException: com.planetj.ser vlet.filter.com pression.Compre ssingServletOut putStream

            what could be the problem????
            That means you are trying to type cast to a type that is incompatible with the type you are casting from.
            Are using a servlet?

            Comment

            • radhikams
              New Member
              • Jan 2008
              • 49

              #7
              Originally posted by r035198x
              That means you are trying to type cast to a type that is incompatible with the type you are casting from.
              Are using a servlet?

              Hi
              I could resolve that problem. i used the HttpServletResp onse obj only..Now its working very fine with .doc , .txt,.xls etc but there is some problem with the .pdf files... when im trying to download it is throwing this exception
              java.net.Socket Exception: Connection reset by peer: socket write error

              What could be teh problem???

              Thanks

              Comment

              Working...