title: How to use jasper-reports with spring MVC?
body: <p>I want to generate a report using jasper-reports and i can't figure what information should contain the controller, because when i a create the report i am using as data source the result set of a query. </p>
  
  <p>reports.jsp</p>
  
  <pre><code>&lt;%@ include file="/WEB-INF/template/taglibs.jsp"%&gt;
  &lt;div class="container"&gt;
      &lt;%@ include file="menu.jsp"%&gt;
      &lt;div class="budgetTable"&gt;
          &lt;div class="form-group "&gt;
              &lt;a class="btn btn-warning buttons generate"
                  href="http://localhost:8080/Catering/index/reports/fullreport/pdf"&gt;Generate
                  full report &lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;a class="btn btn-warning buttons generate"
                  href="http://localhost:8080/Catering/index/reports/partialreport/pdf"&gt;Generate
                  partial report &lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;a class="btn btn-warning buttons generate"
                  href="http://localhost:8080/Catering/index/reports/anotherreport/pdf"&gt;Generate
                  another report &lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>ReportsController.java</p>
  
  <pre><code>package catering.web.controller;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.log4j.Logger;
  import org.springframework.security.core.Authentication;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  
  @Controller
  public class ReportsController {
  
      protected static Logger logger = Logger.getLogger("controller");
  
      @RequestMapping(value="reports", method = RequestMethod.GET)
      public String reportsGet(Model model, Authentication authentication){
  
          logger.debug("Received request to show reports page(GET)"); 
  
          model.addAttribute("username", "You are logged in as " + authentication.getPrincipal());
          return "reports";
      }
  
      @RequestMapping(value = "/reports/fullreport/pdf", method = RequestMethod.GET)
      public ModelAndView fullReport(ModelAndView model){
  
          logger.debug("Received request to download PDF report");
  
          //List&lt;UserModelSummary&gt; users = UserSummaryDataAccess.getUsersSummary();
          //JRDataSource ds = new JRBeanCollectionDataSource(users);
          //Map&lt;String, Object&gt; parameterMap = new HashMap&lt;String, Object&gt;();
          //parameterMap.put("datasource", ds);
          //model = new ModelAndView("pdfReport",parameterMap);
  
          return model;
      }
  
  }
  </code></pre>
  
  <p>jasper-views.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt;
  
      &lt;bean id="pdfReport" class="org.springframework.web.servlet.view.jasperreports.JasperReportsPdfView"
      p:url="classpath:fullReport.jrxml"
      p:reportDataKey="datasource"&gt;
  
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>fullReport.jrxml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version last--&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="fullReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a2f56d0-72e3-4ccf-942d-bf77c76956aa"&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="cateringTest"/&gt;
      &lt;queryString&gt;
          &lt;![CDATA[select u.iduser, u.firstname, u.lastname, u.username from user u]]&gt;
      &lt;/queryString&gt;
      &lt;field name="iduser" class="java.lang.Integer"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="firstname" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="lastname" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;field name="username" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;title&gt;
          &lt;band height="80" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="0" y="60" width="80" height="20" uuid="62c1f51a-4917-456f-8c14-e8df054a02ea"/&gt;
                  &lt;text&gt;&lt;![CDATA[Detailed Report]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/title&gt;
      &lt;pageHeader&gt;
          &lt;band height="35" splitType="Stretch"/&gt;
      &lt;/pageHeader&gt;
      &lt;columnHeader&gt;
          &lt;band height="50" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="0" y="29" width="80" height="20" uuid="5cbcc29e-c1fd-40e2-82b7-4faa4929cedb"/&gt;
                  &lt;text&gt;&lt;![CDATA[ID]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="80" y="30" width="100" height="20" uuid="c6e2fa3b-a346-4a48-b0fd-5381ab527640"/&gt;
                  &lt;text&gt;&lt;![CDATA[First name]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="180" y="29" width="100" height="20" uuid="2fe1f184-f577-4f47-bdf4-661b4d297738"/&gt;
                  &lt;text&gt;&lt;![CDATA[Last name]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="280" y="29" width="100" height="20" uuid="e4187042-e081-4cba-bdd3-ffd54ef3594b"/&gt;
                  &lt;text&gt;&lt;![CDATA[Username]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="25" splitType="Stretch"&gt;
              &lt;textField&gt;
                  &lt;reportElement x="0" y="0" width="100" height="20" uuid="24b51b0e-37f5-4636-910b-ce01fc427ce5"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{iduser}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="80" y="0" width="100" height="20" uuid="d60cbff1-5d4e-45e3-bd0f-ccb833f7165d"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{firstname}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="180" y="0" width="100" height="20" uuid="e6e56077-f6a1-4f23-923e-6eda1937d019"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{lastname}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="280" y="0" width="100" height="20" uuid="697ab4a6-70a3-4eeb-b0fe-842d1b51f754"/&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{username}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
      &lt;columnFooter&gt;
          &lt;band height="45" splitType="Stretch"/&gt;
      &lt;/columnFooter&gt;
      &lt;pageFooter&gt;
          &lt;band height="54" splitType="Stretch"/&gt;
      &lt;/pageFooter&gt;
      &lt;summary&gt;
          &lt;band height="42" splitType="Stretch"/&gt;
      &lt;/summary&gt;
  &lt;/jasperReport&gt;
  </code></pre>