Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4032746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:45:36+00:00 2026-05-20T11:45:36+00:00

I need to open a pdf file for the user who clicks on a

  • 0

I need to open a pdf file for the user who clicks on a download button.

The download button makes a ajax call to a servlet which gets data from a blob field in the database containing PDF contents, and returns it as a response.

What can I do in order to make the response to be downloaded as a PDF file to the user.

The servlet code is as below:

                response.setContentType("application/pdf");
                oracle.sql.BLOB blob = (BLOB) rs.getBlob("MYPDF");
                byte[] bytes = blob.getBytes(1, (int) blob.length());
                ServletOutputStream servletOutputStream = response.getOutputStream();
                servletOutputStream.write(bytes, 0, bytes.length);
                servletOutputStream.flush();
                servletOutputStream.close();

I receive a long response containing characters like the ones below in AJAX when I checked the Fire bug for the response.

�a�J��㔎��ji�2K���y�2��q F�f�9�G��!%�kɂ��W��������mp){h̕�S���NJ_�A����’����2k��j���яR�>wB�e�|=w�p�%w��qǦ>�~�1o�㾙9j�B�;aNx3�`z��طc�O��ï��$�;�N|;�xۇ��;�-�c�f�M��c���(�f�M6K���

I don’t want to submit the page or to popup a window for the servlet with the parameters sent for the query showing in the URL

I also don’t want to create the file on the server.

Is there a way to take the response of servlet coming in ajax call and display it to a page or Iframe and the browser automatically downloads the file…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:45:36+00:00Added an answer on May 20, 2026 at 11:45 am

    Its is NOT possible to download a file using Ajax. However, the same ‘effect’ can be achieved using a hidden IFRAME. Instead of using XMLHttpRequest, dynamically create a hidden iframe and submit it to the servlet with the proper parameters. When the response comes, the browser will automatically handle the content based on the content-type/extension. If you are using jQuery, then this plugin has this functionality in-built.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a pdf file from the HTML provided from database which
I need to open pdf file into browser without Adobe Reader. Is there any
I need to open a pdf file with form texbox included on a form.
I start working on pdf render.I need to open the pdf file inside the
I need to open a pdf file in new browser tab. How to do
i need to open a pdf file from my android app. I have the
I need to open a some types of files like .jpg, word, .pdf when
I need to open documents in the WebBrowser control (SL 4) which is located
I am developing an web application which can upload/download a file from client to
I need to know if there is a way in java/servlet to make documents(doc,pdf)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.