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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:23:19+00:00 2026-05-26T04:23:19+00:00

I am prototyping a web application using Spring MVC 3.0 with JasperReports. I have

  • 0

I am prototyping a web application using Spring MVC 3.0 with JasperReports.
I have already done reporting applications using Spring + Jfreechart + iText + Apache POI and been able to use successfully the respective view classes provided by Spring to stream pdfs, xls and images.

This time I want to try to use JasperReports so that I can design my pdfs outside of the application and not have to worry about knowing the underlying api (be that jfreechart, itext, or poi).

Problem

I have a report1.jrxml file that contains a queryString tag with my query with two date parameters. When I test the report through iReport, it compiles and runs successfully. No problems here.

Now I am reading the JasperReports section from the following Spring documentation http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#view-jasper-reports
and I am trying to get the JasperReportsMultiFormatView to work properly, but there is one piece that I am not understanding:

  1. How does JasperReportMultiFormatView know the database to connect to (Recall that I have the query embedded in the report itself) ?

  2. The documentation states to use the reportDataKey property in the view, but I do not see how this is the solution to my problem.

  3. How do you pass parameters?

What can be done

JaperReports provides with a set of xxxManager objects that are responsible for compiling, fiiling, and exporting the report. You could create a custom class that implements the Spring View interface and do something like this:

Connection connection;
ServletOutputStream servletOutputStream = response .getOutputStream();
InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream("/reports/report1.jasper");
response.setContentType("application/pdf");
Class.forName("com.mysql.jdbc.Driver");
 connection = DriverManager.getConnection("jdbc:mysql://localhost: 
             3306/flightstats?user=user&password=secret");
JasperRunManager.runReportToPdfStream(reportStream,  
                 servletOutputStream, new HashMap(), connection);
connection.close();
servletOutputStream.flush();
servletOutputStream.close();

What I need

I need to accomplish what the code above those leveraging the Spring classes such as JasperReportsPdfView, JasperReportsXlsView, or even better JasperReportsMultiFormatView

So in summary I need to be able to pass the following from my controller to the jasper report:

  1. Parameters
  2. Db connection information so that the queryString inside the jasper knows who to run against

This is what I have and the output is a blank PDF document, I am assuming because it does not know how to run the query

@RequestMapping("/reports/**")
@Controller

public class ReportsController {

@RequestMapping(value ="/reports/usage/report", method = RequestMethod.GET)
public ModelAndView handleSimpleReportMulti(HttpServletRequest request, HttpServletResponse response) throws Exception {

    System.out.println("Made it here");

    Map model = new HashMap();
    //model.put("format", "pdf");
    model.put("START_DATE", new String("09-12-2011"));
    model.put("END_DATE", new String("09-17-2011"));

    return new ModelAndView("report1", model);
}
}
  • 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-26T04:23:19+00:00Added an answer on May 26, 2026 at 4:23 am

    I found the answer to my question. I have changed my controller above to this:

    @RequestMapping(value ="/reports/usage/report/{format}", method = RequestMethod.GET)
    public ModelAndView handleSimpleReportMulti(ModelMap modelMap, @PathVariable("format") String format) throws Exception {
    
        //Map model = new HashMap();
        modelMap.put("format", format);
        modelMap.put("REPORT_CONNECTION", dataSource.getConnection());
        modelMap.put("START_DATE", new String("09-12-2011"));
        modelMap.put("END_DATE", new String("09-17-2011"));
    
        return new ModelAndView("report1", modelMap);       
    }
    

    I have changed my view.properties to this:

    #report1(class)=org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView
    report1(class)=org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView
    report1.url=/WEB-INF/reports/report1.jasper
    

    I hope this helps.

    Thanks

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

Sidebar

Related Questions

I am in the process of prototyping a web application using ruby on rails.
Currently I'm prototyping search with Lucene.Net-2.0-004 on a web application. It's working very well,
I'm designing a web application - prototyping and wireframing the main pages so I've
I have been writing a browser based application (or rather, rapid prototyping an application)
I am prototyping a AJAX based web application running up against ASP.NET, where I
I’m building a mobile web application, and even though I’m still in a prototyping
Do any web 2.0 like websites exist for prototyping object oriented class diagrams?
I am prototyping some C# 3 collection filters and came across this. I have
I'm prototyping the best way to dynamically connect web parts at runtime. Essentailly, the
I am prototyping a windows phone 7 application in silverlight. I am trying to

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.