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 9013077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:09:55+00:00 2026-06-16T03:09:55+00:00

I am trying to send a JasperReports generated PDF file to user’s browser, I

  • 0

I am trying to send a JasperReports generated PDF file to user’s browser, I can’t find what’s wrong in my managed bean method, here’s a snippet:

System.out.println("Making pdf...");

        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ec = fc.getExternalContext();
        String tplPath = ec.getRealPath("testTemplate.jrxml");
        JasperReport jasperReport = JasperCompileManager.compileReport(tplPath);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String,Object>(), ds );

        String pdfName = "/testReport.pdf";
        String pdfPath = ec.getRealPath(pdfName);
        JasperExportManager.exportReportToPdfFile(jasperPrint, pdfPath);

        System.out.println("PDF ready!");

        ec.responseReset(); 
        ec.setResponseContentType(ec.getMimeType(pdfPath)); 
        //ec.setResponseContentLength(contentLength); 
        ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + pdfName + "\""); 

        InputStream input = new FileInputStream(pdfPath);
        OutputStream output = ec.getResponseOutputStream();
        IOUtils.copy(input, output);

        System.out.println("Sending to browser...");

        fc.responseComplete();  

It’s called by a simple user click:

<p:menuitem value="TestPDF" action="#{menuController.getTestPdf()}" />

I feel like it’s something easy to find out. Why can’t I see it? 🙂

  • 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-06-16T03:09:57+00:00Added an answer on June 16, 2026 at 3:09 am

    The <p:menuitem> uses by default ajax. You can’t download files by ajax. JavaScript has due security reasons no facilities to programmatically force a Save As dialogue with arbitrary content in a variable.

    Just turn off ajax.

    <p:menuitem ... ajax="false" />
    

    See also:

    • How to provide a file download from a JSF backing bean?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am trying send an array to php file using $_POST ,still always getting an
I`m trying to send simple html page with form data to user with GET,
I'm trying to send file from a rewritten URL. Inside the .htaccess file I
I am trying to send a pdf as an attachment from Android. Here is
I`m trying to send binary file using socket. FILE *file; char *file_data; file =
Im trying to send a file from my SD using Bluetooth . I'm using
I'm trying to send a file via Zend Framework's (1.10.7) Mail library. $mail =
Am trying to send SMS using PHP file. All email attributes are included on
I am using node.js and trying send the .html file contains these tags: <meta
I'm trying to send an XML file to a server as part of the

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.