Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: No data after downloading pdf BLOB from Oracle db

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy No data after downloading pdf BLOB from Oracle db

    1.I want to download a pdf file which is stored in the oracle db as a blob. But i get 0 kb file.
    I havent done this before. So pls help
    on button click a servlet calls another servlet which does the job of downloading.
    This is the code i wrote to download the file.

    protected void processRequest(HttpServletRequest request, HttpServletResponse resp)
    throws ServletException, IOException {
    resp.setContentType("text/html;charset=UTF-8");
    try {
    OutputStream outStream = resp.getOutputStream();
    List file=(List)request.getAttribute("file");
    String fileName=null;
    byte[] fileBytes=null;
    for (int i=0;i<file.size();i++)
    {
    Map objec=(Map) file.get(i);
    fileName=(String)objec.get("fileName");
    fileBytes=(byte[])objec.get("fileBytes");
    }
    String fileType = fileName.substring(fileName.indexOf(".")+1,fileNam e.length());
    if (fileType.trim().equalsIgnoreCase("pdf"))
    {
    resp.setContentType( "application/pdf" );
    }

    resp.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
    resp.setHeader("cache-control", "must-revalidate");
    System.out.println(fileBytes);
    } finally {
    // out.close();
    }
    }


    Please tell me where i went wrong.How can i download the full pdf file with data?

    2. Lets say this pdf file is a full report of customer details.lets assume its got 300 pages. and for each customer the page no's are known. ex for customer Antony his page no in this pdf is 4 and 5. I want to only download the file with these 2 pages.How can i accomplish this task?




    UPDATE:I solved my first problem which was very silly...just had to add the following lines

    resp.getOutputStream().write(fileBytes);
    resp.getOutputStream().flush();
    resp.getOutputStream().close();

    So i finally succeeded with that. Now pls some1 help me for my second problem.I want to download pages for which page no's are known from the pdf and save as a separate pdf file. Actually thats the pdf i want to download. Not the first pdf. I just did that to learn to download a blob file.
    Last edited by reubenmk; February 23rd, 2012 at 08:46 AM. Reason: solved half the problem


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: No data after downloading pdf BLOB from Oracle db

    This thread has been cross posted here:

    http://www.java-forums.org/java-servlet/55886-no-data-after-downloading-pdf-blob-oracle-db.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to download a pdf file stored in a MySQL blob?
    By A4Andy in forum JDBC & Databases
    Replies: 1
    Last Post: October 20th, 2011, 11:35 PM
  2. Help needed regarding saving BLOB in oracle using JSP
    By smsouvik_2008 in forum JDBC & Databases
    Replies: 1
    Last Post: February 26th, 2010, 02:09 AM
  3. Downloading help with JDK 6
    By oneofthelions in forum Java Theory & Questions
    Replies: 1
    Last Post: December 13th, 2009, 07:36 AM
  4. Java program for downloading contents from the web
    By alley in forum Java Networking
    Replies: 8
    Last Post: June 17th, 2009, 01:13 PM
  5. How to know number of user downloading an application?
    By jazz2k8 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 3rd, 2008, 04:34 AM

Tags for this Thread