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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:10:26+00:00 2026-05-22T01:10:26+00:00

This is the controller class @Controller public class ReportController { @RequestMapping(/reports.htm) public void onSubmit(ModelMap

  • 0

This is the controller class

@Controller
public class ReportController {
    @RequestMapping("/reports.htm")
    public void onSubmit(ModelMap map, HttpServletResponse response) {

        PayrollService ps = new PayrollServiceImpl();

        JRBeanCollectionDataSource jr = new JRBeanCollectionDataSource(ps.listAllLoans(), false);
        try {
            JasperPrint jp = JasperFillManager.fillReport(new FileInputStream("C:\\Documents and Settings\\Administrator\\workspace\\payroll\\WebContent\\WEB-INF\\payrollReports\\report2.jasper"), null, jr);
            JRExporter jre = new JRPdfExporter();
            jre.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "report.pdf");
            jre.setParameter(JRExporterParameter.JASPER_PRINT, jp);

            ServletOutputStream output = response.getOutputStream();
            jre.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
            jre.exportReport();

            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

When I run this, A dialog box opens asking to download file, reports.htm, when I open the file, I get this

%PDF-1.4 %âãÏÓ 3 0 obj <>stream xœ+är á26S°00SIár á

ä2Rð‰!ˆ´01RÉåÒw3T0²Ò¸44C²@jJ’s‘5Z˜[ë™!t€t€å‹Ò¹4¼‹R‹@(¤c1,:H§€ƒÇCs3C<Ö˜êè*XX˜(8úe p7E
endstream endobj 1 0 obj<>/Parent 4 0
R/Contents 3 0
R/Type/Page/Resources<>/Font<>>>/MediaBox[0
0 595 842]>> endobj 5 0 obj[1 0 R/XYZ
0 854 0] endobj 2 0 obj<> endobj 4 0
obj<> endobj 6 0 obj<> endobj 7 0
obj<> endobj 8 0 obj<>/Pages 4 0 R>>
endobj 9 0 obj<> endobj xref 0 10
0000000000 65535 f 0000000220 00000 n
0000000487 00000 n 0000000015 00000 n
0000000574 00000 n 0000000453 00000 n
0000000624 00000 n 0000000677 00000 n
0000000708 00000 n 0000000810 00000 n
trailer
<<9f3f4526709d5e33fd22d07da10c3883>]/Info
9 0 R/Size 10>> startxref 976 %%EOF

But when I save the file and open with adobe PDF, I get the correct PDF.
How can I download reports.pdf instead of reports.htm?

  • 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-22T01:10:26+00:00Added an answer on May 22, 2026 at 1:10 am

    Set the Content-Disposition and Content-Type headers to instruct the browser how to handle the resource.

    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=\"report.pdf\"");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
I've this controller public class AdminController : Controller { private IAdministratorService _administratorService; public AdminController(IAdministratorService
Lets say I have a controller class like this. public class InStorePickupController : Controller
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
Ok i have this controller: class ExampleController extends AppController { var $name = 'Example';
Say I have a class that wraps the Controller class: public class MyController :
Controller class: public class PlantHeadController : Controller { private WOMSEntities2 db = new WOMSEntities2();
iam having controller like below which is not registered in routes table public class
In our code we used to have something like this: *(controller->bigstruct) = ( struct

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.